Some ISO date handling in Extjs

This is an excellent website for making tests w.r.t. date/time millisecond conversion: http://currentmillis.com/

/*global Ext:false */

Ext.application({
launch: function () {
var st_iso_date = 
    Ext.Date.parseDate("2014-03-01 22:00:00", "Y-m-d H:i:s");
var end_iso_date = 
    Ext.Date.parseDate("2014-04-01 22:00:00", "Y-m-d H:i:s");
console.log(st_iso_date,st_iso_date.getTime());
    //Sat Mar 01 2014 22:00:00 GMT+0000 (GMT) 1393711200000
console.log(end_iso_date, end_iso_date.getTime());
    //Tue Apr 01 2014 22:00:00 GMT+0100 (BST) 1396386000000
var difference_ms = 
    Math.abs(end_iso_date.getTime()-st_iso_date.getTime());
var ONE_DAY=86400000;//1000 * 60 * 60 * 24
console.log( difference_ms/ONE_DAY); 
}});

I should also say thank you to This guy

Leave a Comment

Using Imagemagick to convert images in sencha touch

The file below is for Mac or Linux.

usage: con.sh inputfile.fmt

e.g.

$  con.sh Karl.png

creates all the formatted icons in the output folder

create the file con.sh in the project root of sencha project folder. with the following contents.

 

#!/bin/bash
#This file must be in project root

PTH=”resources/icons/”
convert=”convert -background none”
$convert “$1″ -resize 36×36 “$PTH/Icon_Android36.png”
$convert “$1″ -resize 48×48 “$PTH/Icon_Android48.png”
$convert “$1″ -resize 50×50 “$PTH/icon-spot~ipad.png”
$convert “$1″ -resize 57×57 “$PTH/Icon.png”
$convert “$1″ -resize 114×114 “$PTH/Icon@2x.png”
$convert “$1″ -resize 72×72 “$PTH/Icon~ipad.png”
$convert “$1″ -resize 144×144 “$PTH/Icon~ipad@2x.png”
$convert “$1″ -resize 500×500 “$PTH/iTunesArtwork.png”

When file is created run chmod +x

Leave a Comment

Can the power of a human swarm find the missing plane flight MH370?

Can the human swarm find this plane?
This is not meant to be politically incorrect and something I put together in a short timeframe using Google Cloud (never used it before).

S16.03.28

The familiar map shown on the news channels

The human swarm is a powerful thing but this exercise is limited due to the amount of information and the not really knowing whay goes on in the head of the person(s) who manually took charge of the plane. Anyway, who knows.

Where do the public think this plane is?

Where do the public think this plane is?

Maybe put your mark on the map. Just captures the Longitude and lattitude of where you think the plane may be (oh and your IP address to avoid attacks).

Please though, if you have a go, think about all you have read and heard so far, weigh it up in your head and click where you think it will be.

The results page will get updated when I get round to it. (I was using new tech and had little time for this exercise so please bear with me).

Find MH370

Code

index.html

This is the landing page. Note the array (waypoints) which are easily updatable. I included the last known transmission point, the aircraft range (before it could run out of fuel) and the debris – a small white spot outside the range circle. So if the plane was high up and cruised down on no fuel it is conceivable the debris is where it is.

<html lang="en">
<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body>
  <div class='main'>
  <style type="text/css">
  .eventtext {width:600px; margin-top:20px; font:10pt Arial; text-align:left; line-height:25px; background-color:#EDF4F8;
   padding:5px; border:1px dashed #C2DAE7;}
  #coodiv {width:600px; margin-left:5px;height:800px; border:5px solid #DEEBF2;}
  #mapdiv {width:600px; height:800px; border:5px solid #DEEBF2;}
  ul {font:10pt arial; margin-left:0px; padding:5px;}
  li {margin-left:0px; padding:5px; list-style-type:decimal;}
  .small {font:9pt arial; color:gray; padding:2px; }
  #latlongclicked {width:600px; border:1px inset gray;}
  </style>
<div>
  <h2>Missing plane MH370 - please click where you think it is   - So far:<A href="http://23.251.144.208/sofar.html">Results</A></h2>
<div style="float:left; position:relative;" id="mapdiv"></div>
<div style="float:left; position:relative;" id="coodiv">ddd</div>
<div class="eventtext">
<div>Latitude: <span id="latspan"></span></div>
<div>Longitude: <span id="lngspan"></span></div>
<div>Lat Lng on click:
  <input type="text" id="latlongclicked"></span></div>
</div>
</div>
<script>
var map
var waypoints = {};
waypoints['lasttransmission'] = {center: new google.maps.LatLng(5.536277,102.19834),sz:5000000,clr:'#ff0000'};
waypoints['range'] = {center: new google.maps.LatLng(5.536277,102.19834),sz:40000,clr:'#00FF00'};
waypoints['debris'] = {center: new google.maps.LatLng(-43.942778,90.959444),sz:60000,clr:'#FFFFF0'};

function mapa()
{
    var opts = {'center': new google.maps.LatLng(5.536277,102.19834),
    'zoom':3, 'mapTypeId': google.maps.MapTypeId.HYBRID }
    map = new google.maps.Map(document.getElementById('mapdiv'),opts);
    google.maps.event.addListener(map,'click',function(event) {
      document.getElementById('latlongclicked').value = event.latLng.lat() + ', ' + event.latLng.lng()
      var objData = {};
      objData.lg=event.latLng.lng()
      objData.lt=event.latLng.lat();
      $.ajax({
        url: 'plane.php',
        type: 'POST',
        data: objData,
        dataType: 'json',
        success: function(data,status){}, 
        error: function(response){}
      })
        window.location.href = "sofar.html";
    });

    for (var wp in waypoints) {
        var wpOptions = {strokeColor: waypoints.clr,strokeOpacity: 0.5,strokeWeight: 2,fillColor: waypoints.clr,
        fillOpacity: 0.1,map: map,center: waypoints.center,radius:waypoints.sz,clickable: false
        };
        wpCircle = new google.maps.Circle(wpOptions);
    }
    google.maps.event.addListener(map,'mousemove',function(event) {
       document.getElementById('latspan').innerHTML = event.latLng.lat()
       document.getElementById('lngspan').innerHTML = event.latLng.lng()
    });
}
window.onload = mapa
$( "#coodiv" ).load( "thedetails.html" );
</script>
</body></html>

results.html

Would not recommend making this a public file as it could kill the database if loads of results come in and they are shown to each user each time they click the map. This is used to generate an image that can be updated hourly. Actually, it didn’t really matter as people didn’t really take up the swarm phenomena in this case and there was only about 30 hits in 24 hours.

<html lang="en">
<head>
<script  src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body>
<div class='main'>
<style type="text/css">
.eventtext {width:100%; margin-top:20px; font:10pt Arial; text-align:left; line-height:25px; background-color:#EDF4F8;
padding:5px; border:1px dashed #C2DAE7;}
#mapdiv {width:600px; height:800px; border:5px solid #DEEBF2;}
ul {font:10pt arial; margin-left:0px; padding:5px;}
li {margin-left:0px; padding:5px; list-style-type:decimal;}
.small {font:9pt arial; color:gray; padding:2px; }
#latlongclicked {width:600px; border:1px inset gray;}
</style>
 <div id="mapdiv"></div>
<script>
var map
function mapa()
{
   var opts = {'center': new google.maps.LatLng(5.536277,102.19834),
   'zoom':3, 'mapTypeId': google.maps.MapTypeId.HYBRID }
   map = new google.maps.Map(document.getElementById('mapdiv'),opts);
   $.getJSON('mapdata.php', function(data) {
     $.each(data, function(index, element) {
        new google.maps.Marker({
          map: map,
          position: new google.maps.LatLng(element.lat,element.lon)
        });
      });
   });
}
window.onload = mapa
</script>
</body>
</html>

sofar.html

This page displays a graphic of the preloaded markers as a png. This way the database is not beaten to death. sofar.html gets loaded as the result of the user clicking the map. Note in the configuration of the markers, clickable=false was set. By default the marker would be responsive to a mouse click. Since the big aircraft range marker spanned a diameter if thousands of miles, it would mean the mousemove event would not fire due to being obscured by the giant opaque marker.

<html lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div class='main'>
<style type="text/css">
.eventtext {width:600px; margin-top:20px; font:10pt Arial; text-align:left; line-height:25px; background-color:#EDF4F8;
padding:5px; border:1px dashed #C2DAE7;}
#coodiv {width:600px; margin-left:5px;height:600px; border:5px solid #DEEBF2;}
#mapdiv {width:600px; height:600px; border:5px solid #DEEBF2;}
ul {font:10pt arial; margin-left:0px; padding:5px;}
li {margin-left:0px; padding:5px; list-style-type:decimal;}
.small {font:9pt arial; color:gray; padding:2px; }
#latlongclicked {width:600px; border:1px inset gray;}
</style>
<div>
<h2>Missing plane MH370 - where the public thinks it is</h2>
<div style="float:left; position:relative;"   id="mapdiv">
<img src="sc.png" >
</div>
<div style="float:left; position:relative;"  id="coodiv">At 2014-03-20 09:40 GMT</br>If you just added a location then thanks for your input. If you did not yet do it please go here <a href="http://23.251.144.208/index.php">Here</a> and click on the map.</br>Please come back to http://23.251.144.208/sofar.php for updates</div>
<script>
$( "#coodiv" ).load( "thankyou.html" );
</script>
</body></html>

Database schema

CREATE TABLE `swarm` (
  `ipaddr_r` char(45) NOT NULL,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `lon` double NOT NULL,
  `lat` double NOT NULL,
  `ipaddr_p` char(45) NOT NULL,
  UNIQUE KEY `ipaddr` (`ipaddr_r`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

plane.php

We catch the ip address of the person who clicked and this is stored as a unique key.
When the code is executed it deletes any previous record of the click from that IP, if it exists.
A new row is added with unique IP. Doing it this way helps prevent someone spamming the database (unless they spoof a different IP each time) and also gives the user a chance to change their mind and replace their existing thought.

<?php
include 'connectinfo.php';
$lg = $mysqli -> real_escape_string($_POST['lg']);
$lt = $mysqli -> real_escape_string($_POST['lt']);
$ipp=$_SERVER['HTTP_X_FORWARDED_FOR'];
$ipr=$_SERVER['REMOTE_ADDR'];
if (strlen($ipp) == 0)$ipp="--"; // not always going to get this but db constraint is not blank
//record all in a temp file - not for production!
 file_put_contents("/tmp/allplane.txt", "planedata: IPP=$ipp IPR=$ipr $lg $lt",FILE_APPEND);

 if ($delete_stmt = $mysqli -> prepare("DELETE FROM swarm WHERE ipaddr_r = ?")){
   $delete_stmt -> bind_param('s',$ipr);
 if ($delete_stmt -> execute()) ; // handle good
   else ; // handle bad. No handlers were put in this code
}	       
	       
if ($insert_stmt = $mysqli -> prepare("INSERT INTO swarm(ipaddr_r,ipaddr_p,lon,lat) VALUES (?,?,?,?)")){
		$insert_stmt -> bind_param('ssss',$ipr, $ipp, $lg,$lt);
 		if ($insert_stmt -> execute()) ; // good				   
        else ;// do something with $insert_stmt -> error maybe
} else 
    ; // do something with $insert_stmt -> error;
echo "OK"; // as it stands the form does not get back valid data so the POST will raise an error but you don't see that
?>

mapdata.php

This tiny php file gets a json array of longitude and latitude points from the map.

<?php
include 'connectinfo.php';
$query = "SELECT lon,lat FROM swarm"; 
$result = $mysqli -> query($query);
for ($set = array (); $row = $result->fetch_assoc(); $set[] = $row);

  echo json_encode($set);
/* free result set */
$result -> free();

/* close connection */
$mysqli -> close();
?>

Notes

Not going to go into details about whats in connectinfo.php because how to connect to a mysql db is all over the internet.

Disclaimer

This is not production quality and was done in lightening speed on a small google vm instance and a separate SQL server in google’s cloud.
I’d never used google before for cloud stuff so had to learn a few things. I’ve used Amazon AWS before which is also good but I think google is my platform of choice and learned a lot from this exercise.

Leave a Comment

Ford Insure – a cycle of negligence and risk

November 2011:

I insured my brand new Kuga with Ford Insure.

19th January 2012:

Stopped by police on M6 for “having no insurance”. The car was to be taken by the police unless I can get an insurance policy set up there and then. Ford Insure denied to the police officer any claim that I made previous insurance arrangements with them but agreed with me to set up a policy road-side which the officer verified before I could leave. I was handed a ticket for having no insurance!

On completion of my journey I contacted Ford Insure who continued to deny me ever taking up a policy but agreeing that I had spoken to them but not followed through with the insurance on the phone. I knew I had and so requested under the terms of the Data Protection Act for them to provide me a copy of every conversation with their staff in relation to the insurance of the named vehicle. 

23rd January 2012: 

A letter arrived.

Reference: RSAP6719753200 from Tom Bailey, Technical Customer Manager “To whom it may concern” to quote, “we would have honoured our obligations“. This was sent to the Magistrates Court and the matter was closed and I did not receive 6 points on my license and a heavy fine.

Nearly two years later I decided to sell the car privately (because the Ford Dealership wanted to offer me £2,400 less than what the vehicle was worth). I wanted to sell the Ford Kuga because it, despite the sales propaganda, there was no way to achieve the urban or motorway MPG at the published figures unless the vehicle was driven in a vacuum so I felt cheated by Ford and wanted to indefinitely cut ties with the company.

I called Ford Insure in November 2013 and formally cancelled the policy and gave my reasons for doing so – which was because I had sold the car. A letter arrived over the Christmas period from Premium Credit stating that I had to sign an agreement for them to continue taking payments from my account. I ignored this putting it down to the fact that clearly Ford continues to be in a muddle but will no doubt come to its senses. Without my authority, without the required signature, money started to be taken out of my account by Premium Credit so a visit to the bank resulted in the refund on £70+ of the stolen money and I was to begin a process of resolving the matter. I got beaten to it because today, by recorded delivery, I received this letter threatening me with legal action to recover their losses.

 

 

I look forward no to a visit from the bailiffs courtesy of the grossly negligent Ford Insure people.

Leave a Comment

Protected: Network post-clone activites (MAC-ADDRESS, 70-*) VirtualBox Centos 6.4

This content is password protected. To view it please enter your password below:

Enter your password to view comments.

Protected: Oracle Client 32bit on Centos 6.4 install-issue resolution and firewall provisioning

This content is password protected. To view it please enter your password below:

Enter your password to view comments.

Protected: http local yum local mirror, cron job, repo

This content is password protected. To view it please enter your password below:

Enter your password to view comments.

Older Posts »
Follow

Get every new post delivered to your Inbox.