Low tech male/female voice detection system

I was drinking a bootle of water, while listening to a group of people having a debate. As the water level sunk, I noticed something. In the beginning the bottle would resonate/vibrate when the people with higher pitch voices talked. When the bottle was nearly empty, it would resonate/vibrate (and more so) when people with bassier voices talked.

Using bottles of water (with different waterlevels) and a vibration sensor on each, one could make a low tech thing that detects whether a male or female is speaking in the room. Why not use a microphone and a spectrum analyzer? Well, because you are McGyver and you’re caught in some prison, and mission dictates that you find out when the guy with the really bassy voice enters the room. You know, ad hoc spy stuff.

Here is a figure that illustrates the “Low Tech Male/Female Voice Detection System”:

Really easy 3D graphics in LaTeX

Note: The word “easy” is relative to the other solutions I found for doing 3D graphics in LaTeX.

The following template is adapted from the annotated 3d box example.

% Template for drawing with tikz 3D package
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{3d}
 
\begin{document}
 
% Draw a 3D coordinate system
 
\begin{center}
\begin{tikzpicture}[x  = {(1cm,0cm)},
                    y  = {(0.4cm,0.6cm)},
                    z  = {(0cm,1cm)},
                    scale = 1,
                    color = {lightgray}]
 
\begin{scope}[canvas is xy plane at z=0]
  % x-axis
  \draw[blue,->] (0,0) -- (5,0) node (x-axis) [right] {$x$};
  % y-axis
  \draw[red,->] (0,0) -- (0,5) node (y-axis) [above] {$y$};
\end{scope}
 
\begin{scope}[canvas is yz plane at x=0]
  % z-axis
  \draw[green,->] (0,0) -- (0,5) node (z-axis) [above] {$z$};
\end{scope}
 
\end{tikzpicture}
\end{center}
\end{document}

Read more

How to load an ESRI Shapefile into a PostGIS DB

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”.

Using shp2pgsql

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.

Using ogr2ogr

This is even easier with ogr2ogr:

ogr2ogr -f "PostgreSQL" PG:"host=localhost user=dbuser dbname=mydb password=secret" -lco SCHEMA=xyz myshapefile.shp

Hello world plugin for Nagios in Python

Nagios looks at 1) return codes and 2) output to stdout. This is the hello world of Nagios plugins, written in Python:

check_helloworld.py:

#!/usr/bin/env 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

Read more

Saving output from ‘text to speech’ to a file on Mac OS X

In terminal you can write something like:

say 'hello world'

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'
open hello.aiff

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.

Kill process from within top in Terminal on Mac OS X

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:

sudo top

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.

Installing pip and virtualenv on Mac

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).

Installing pip

(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

Read more