How to record and convert real audio streams to mp3

I came up with this one a long time ago - its a nice little hack. It requires mplayer (and the right codecs) and lame. It might work on windows if you have cygwin installed. It should work with any type of stream that mplayer can play, not just real audio streams.

This approach uses a fifo virtual file to make sure that you don’t waste disk space storing raw audio data. It just pushes the audio data into the fifo, and lame pulls it out all asynchronously.


mkfifo soundpipe
lame -b 64 soundpipe filename.mp3 & mplayer -quiet -ao pcm -aofile soundpipe URL_OF_STREAM

Lighttpd on ubuntu

Lighttpd is a great web server. It manages resources frugally, and still manages to be fast. If you have a dedicated super duper server, lighttpd is probably not for you. But perhaps you need your machine to do more than just be a web server, or perhaps you are using a virtual dedicated server (vds, vps, whatever they are called - I use slicehost which is great and inexpensive) which means you have a limited amount of ram and cpu. In that case, lighttpd is a great choice for your web server. The main downside, is that it isn't quite as plug and play as apache is. Apache pretty much runs php out of the box, and installing phpmyadmin just works. There are plenty of guides for getting rails to work with lighttpd, but I couldn't find anything very useful for lighttpd and php (especially with fast-cgi). At any rate, I figured out how to set it in Ubuntu (dapper) and figured I would pass share the experience:

Install php with fast-cgi and lighttpd


sudo apt-get install php4-cgi lighttpd
sudo lighty-enable-mod (then select fast_cgi)

sudo gedit /etc/lighttpd/conf-enabled/10-fastcgi.conf


And change the port line to be this instead: (this seems to be a bug in the default ubuntu configuration)

socket => "/tmp/php.socket"


Now restart lighttpd

sudo /etc/init.d/lighttpd reload


Final step: Take over world


Get phpmyadmin to work with lighttpd
(The following steps assume that you have done part 1 properly)

sudo apt-get install phpmyadmin php4-mysql
sudo gedit /etc/lighttpd/lighttpd.conf


And add an alias for phpmyadmin


alias.url = ("___invalid .... other stuff here
"/phpmyadmin/" => "/usr/share/phpmyadmin" # this is the line to add
)


Reload the server:
sudo /etc/init.d/lighttpd force-reload


(might also need to edit /etc/php.ini and enable mysql, but it might happen automatically too)

Quick and dirty debug logging in ruby on rails

Typically I just to render :text=> "Yo the value is #{debug_me}" and return

But sometimes this doesn't work. Maybe you are in a model file, or a method that gets returned to another method. If that is the case you can always get some debug by raising an exception:

raise "Yo the value is#{debug_me}"

Since exceptions can come from anywhere this will always works. There are other options, like using logger which works pretty well too - but raising an exception is a nice debug hack for your toolkit.