Sunday, December 26, 2010

Command-line tools on Mac OS X, Snow Leopard

allmemory, fs_usage, fuser, latency, sar, sc_usage, spindump: Display various system usage statistics.

bless, disklabel, disktool, diskutil, drutil, fsck, hdiutil, pdisk: Create, identify, manage, and fix Mac OS X disks, file systems, and disk images.

ioreg, kextstat: Show device drivers and other kernel extensions in use.

mDNS, dns-sd: Test Bonjour service discovery with these diagnostic tools.

open: Invoke launch services on an arbitrary document or application as if doubleclicking it in the Finder.

pbcopy, pbpaste: Move data between stdin/stdout and the Mac OS X pasteboard.

say: Convert text to audio output or a file via Speech Synthesizer.

shasum: Compute or validate SHA message digests.

sips: Manipulate the format and color space of bitmap images (for example, rotate,

sw_vers, uname: Display Mac OS X version information.

syslog and logger: Send, view, and manage system log messages with these modern

xattr: List, display, set, and delete file system extended attributes

You can find more information on apple.com in this documentation.

Tuesday, December 21, 2010

snoop file opens on Snow Leopard

Opensnoop tracks file opens.
sudo opensnoop

or you can watch only a process
sudo opensnoop -n Google Chrome

HTML5 heading elements

"In HTML 4, the only way to create a document outline was with the <h1>–<h6> elements. If you only wanted one root node in your outline, you had to limit yourself to one <h1> in your markup.
But the HTML5 specification defines an algorithm for generating a document outline that incorporates the new semantic elements in HTML5.
The HTML5 algorithm says that an <article> element creates a new section, that is, a new node in the document outline. And in HTML5, each section can have its own <h1> element."


more of Pilgrimさん's Dive into HTML5
or check the outline of your document with the HTML5 Outliner

activemq and the java.io.EOFException: Chunk stream does not exist at page: 0

If you start activemq and get an error like that

INFO | Scheduler using directory: activemq-data/localhost/scheduler
ERROR | Failed to start ActiveMQ JMS Message Broker. Reason: java.io.EOFException: Chunk stream does not exist at page: 0
java.io.EOFException: Chunk stream does not exist at page: 0

It means that there is something wrong with the scheduler.

If you don't use the built in persisten scheduler you can easily turn it off by changing the activemq.xml config file (/opt/local/share/java/activemq/conf/activemq.xml)

<broker xmlns="http://activemq.apache.org/schema/core" ....
to
<broker xmlns="http://activemq.apache.org/schema/core" schedulerSupport="false">

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