Assuming a shapefile called myshapefile.shp, a table mytable in schema xyz, in a PostGIS enabled database called mydb on localhost. The table is owned by user dbuser who has password “secret”.
shp2pgsql myshapefile -I xyz.mytable > statements.sql
psql -d mydb -h localhost -U dbuser -f statements.sql
This tip and many more can be read in Making Maps Fast.
This is even easier with ogr2ogr:
ogr2ogr -f "PostgreSQL" PG:"host=localhost user=dbuser dbname=mydb password=secret" -lco SCHEMA=xyz myshapefile.shp
tikZ and LaTeX
PGF/TikZ is a tandem of languages for producing vector graphics from a geometric/algebraic description. You can use this language inside tex files, to programmatically draw nice 2D and 3D graphics. Another package which some people prefer for 3D is asymptote.
Read the manual.
Continue reading “Howto make 3D graphics in LaTeX with tikz”
Choose the appropriate sourcecode version by going to http://nodejs.org/#download.
wget http://nodejs.org/dist/v0.6.7/node-v0.6.7.tar.gz # or use curl
Continue reading “Installing Node.js on EC2 64-bit microinstance running Amazon Linux”
Nagios looks at 1) return codes and 2) output to stdout. This is the hello world of Nagios plugins, written in Python:
# optparse is Python 2.3 - 2.6, deprecated in 2.7
# For 2.7+ use http://docs.python.org/library/argparse.html#module-argparse
from optparse import OptionParser
# CONSTANTS FOR RETURN CODES UNDERSTOOD BY NAGIOS
# Exit statuses recognized by Nagios
UNKNOWN = -1
OK = 0
WARNING = 1
CRITICAL = 2
# TEMPLATE FOR READING PARAMETERS FROM COMMANDLINE
parser = OptionParser()
parser.add_option("-m", "--message", dest="message",
default='Hello world', help="A message to print after OK - ")
(options, args) = parser.parse_args()
# RETURN OUTPUT TO NAGIOS
# USING THE EXAMPLE -m PARAMETER PARSED FROM COMMANDLINE
print 'OK - %s' % (options.message)
raise SystemExit, OK
Continue reading “Hello world plugin for Nagios in Python”
In terminal you can write something like:
Which will make your computer talk. To save the audio output to a file, use the -o option. A full example is:
say -o hello.aiff -v 'Alex' 'Hello, my name is Alex'
This will say ‘Hello, my name is Alex’, in the voice of ‘Alex’ (other voice-options are ‘Bruce’, ‘Fred, ‘Kathy’, ‘Vicki’ and ‘Victoria’), and save the output to ‘hello.aiff’.
It seems there is no option for setting the speed (can be set in System preferences -> speech). See man say for all options. Interesting options include sending the output over the network.
My top seems to act a little strange (running Snow Leopard). It doesn’t respond to the key commands I’m used to, e.g. for sorting on Memory Usage etc. Nevertheless, this is how I found out (by chance really) how to kill a process from within top.
First start top using sudo:
Press shift + s. This will promt for a signal. Enter the word ‘kill’ (if not already selected). Hit enter. Now top prompts for a pid. Enter the pid of the process you want to expedite. Hit enter. Good bye process.
These instructions show how to install pip and virtualevn on a Mac running Snow Leopard 10.6.8 and using Python 2.7. I used this to install Django 1.3.1 (installation instructions included).
(skip if you have pip installed)
First make sure you have either setuptools or distribute installed. Please consult your operating system’s package manager or install it manually:
curl http://python-distribute.org/distribute_setup.py | python
Continue reading “Installing pip and virtualenv on Mac”
Here’s a game I like to play. Select two wikipedia pages at random, and find a route from one to the other. I stated a theorem once that:
you can get from any page on wikipedia to the page on pollination in 7 steps or less. (it was actually another page, but let’s say it was pollination)
I devised a method for doing this using Google search. Let’s call the random page s, and the page you want to reach t, e.g. pollination. A given page on wikipedia has a set of incoming links (other pages linked to the page), and a set of outgoing links (other pages linked to by the page). Let’s call these two sets in[p] and out[p]. These two sets contain direct decendants and ancestors of p respectively.
Continue reading “Finding a route from one wikipedia page to another”
This howto shows how to get Nagios up and running on an Amazon EC2 Instance using Apache web server to serve the Nagios UI. You could argue that a more light-weight web server would be better, but I’d argue that it doesn’t really matter. Performance is not a great issue for a few administrators looking at the Nagios UI.
Continue reading “Running Nagios on Amazon EC2”
Google Fusion Tables is a service for storing tabular data online. It has an API that allows you to make an SQL-like request for data from an online table, like the following: sql=SELECT * FROM 1906375 (clicking the link will download a small CSV file)
Continue reading “CORS and Google Fusion Tables”