Simple CSV file import
You have a CSV file called “data.csv”. It has a header line, and is delimited using “;”. You want to import it into Postgres and a table called “your_table”:
Create the database table. Set column-types so the string fields in the CSV file, can be cast to values in columns.
CREATE TABLE your_table
-- Your columns
Continue reading “Importing data from a CSV file into a Postgres table”
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
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”
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”
Introduction to CORS
CORS (Cross Origin Resource Sharing) is a mechanism specifies by W3C (draft), for allowing browsers to make cross origin requests for resources on other domains under certain conditions. It’s related to JSONP because it solves a similar problem, namely loading data from one domain, into a web application running on a different domain. A difference is that CORS supports the full palette of HTTP verbs, not just GET.
See also: http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
Continue reading “Using CORS instead of JSONP to make cross site requests”
I keep forgetting how to do this.
How to group on a date column (date_col in the example) in Oracle:
SELECT COUNT(*) FROM TABLE GROUP ON TO_CHAR(date_col, 'DD-MON-YYYY HH:MI:SS')
For other format strings than
see this page.
There is a good little tool called s3funnel on GitHub for this. I used easy_install to install on my Mac.
Continue reading “how to delete/empty S3 bucket with many objects”
E.g. to select rows with a timestamp on minutes 0, 5, 10, …, 55
SELECT * FROM t WHERE MOD(to_number(to_char(date_time_col, 'mi')),5)=0