Monday, December 20, 2010

Open a new tab with AppleScript in Chrome

tell application "Google Chrome"
set myTab to make new tab at end of tabs of window 1
set URL of myTab to "http://google.com"
end tell


more AppleScript Chrome goodies at http://laclefyoshi.blogspot.com/2010/10/google-chrome-ver.html

Get user id on a remote server

you have to use SSH public/private key pairs to make this work.

#!/bin/bash
uid=`ssh <your.server> 'id -u'
echo $uid

more stuff here http://bashcurescancer.com/run_remote_commands_with_ssh.html

Google App Engine Development Console from command line

When you develop on localhost the interactive console that Google provides is not convenient.
In my project I had to run few scripts in the console quite often, so instead of going to the interactive console all the time I could do it from command line.

This example executes the 'gen_pilot_data.py' script on the interactive console.

curl --data-urlencode "code=`cat src/gen_pilot_data.py`" http://localhost:8079/_ah/admin/interactive/execute

Please notice that you may have to the change the port number.

Sunday, December 19, 2010

Latitude and longitude of cities

http://www.getlatlon.com

cities = [
{ 'name': 'Tokyo', 'lat': 35.6894875, 'lon': 139.6917064 },
{ 'name': 'Seoul', 'lat': 37.566535, 'lon': 126.9779692 },
{ 'name': 'Beijing', 'lat': 39.904214, 'lon': 116.407413 },
{ 'name': 'New Delhi', 'lat': 28.635308, 'lon': 77.22496 },
{ 'name': 'Moscow', 'lat': 55.755786, 'lon': 37.617633 },
{ 'name': 'Kiev', 'lat': 50.45, 'lon': 30.5233333 },
{ 'name': 'Budapest', 'lat': 47.4984056, 'lon': 19.0407578 },
{ 'name': 'Berlin', 'lat': 52.5234051, 'lon': 13.4113999 },

{ 'name': 'Paris', 'lat': 48.8566667, 'lon': 2.3509871 },
{ 'name': 'Madrid', 'lat': 40.4166909, 'lon': -3.7003454 },
{ 'name': 'New York', 'lat': 40.7143528, 'lon': -74.0059731 },

{ 'name': 'Mexico City', 'lat': 19.4270499, 'lon': -99.1275711 },
{ 'name': 'Honolulu', 'lat': 21.3069444, 'lon': -157.8583333 },

{ 'name': 'Sydney', 'lat': -33.8599722, 'lon': 151.2111111 },
{ 'name': 'Taipei', 'lat': 25.091075, 'lon': 121.5598345 }
]

Friday, December 17, 2010

Zoom to fit all markers with Google Maps V3


// creating the map
var map = new google.maps.Map(document.getElementById("map_canvas"), {
mapTypeId: google.maps.MapTypeId.ROADMAP
});

// latitude, longitude values
var latLons = [ { lat: 35.6453962, lon: 139.7117893 },
{ lat: 35.645076, lon: 139.709183 } ];

// this is the bounding box container
var bounds = new google.maps.LatLngBounds();

// iterating through the points
latLons.forEach( function (element, index, array) {

var point = new google.maps.LatLng(element.lat,element.lon);

// extending the bounding box
bounds.extend(point);

// creating the marker on the map
var marker = new google.maps.Marker({
position: point,
map: map
});
});

// zooming on the map
map.fitBounds(bounds);

Tuesday, December 14, 2010

Reload the browser with AppleScript

This post is obsoleted, here is the new simplified version.

AppleScript is a weird language but you still can do cool things with it.

tell application "Google Chrome"
activate
end tell

tell application "System Events"
tell process "Google Chrome"
keystroke "r" using {command down}
end tell
end tell


Please feel free to replace "Google Chrome" with your choice.

https://github.com/yikulju/MacGyver/blob/master/reload-browser.applescript

removing trailing whitespace with sed


sed -i '' -e's/[ \t]*$//' $1


the full script can be found here
https://github.com/yikulju/MacGyver/blob/master/rwh.sh