Archive
Memcached Pool Bash Start Script
If you installed Memcached using Yum under the RedHat flavor of Linux, they have this really nice init.d scripts for starting and stopping Memcache. I modified it in order to support creating a bunch memcache instances using contiguous ports. What’s great is that only the “start” script has to be modified since the “stop” script uses a special RedHat function, killproc, which can accept a program name or path and kill all instances of that program. I’m still a noob at bash scripts but here is my only changes:
NUMBUCKETS=3 #only new value needed start() { for ((i=1;i<=$NUMBUCKETS;i+=1)); do FULLPORT=${PORT}${i} echo -n $"Starting $FULLPORT ($prog): \n" daemon $prog -d -p $FULLPORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS RETVAL=$? done echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog return $RETVAL }
Vim Tips
Since switching to Linux, I have slowly fallen in love with Vim. I love how Vim makes it so that “your hands should never have to leave your keyboard” (Chris). The biggest drawback to using Vim, and Emacs, is that there’s a fairly steep learning curve. You pretty much have to abandon your comfort zone and force yourself to learn all of the different key bindings.
I’m very lucky in that I work with two vim gurus: Chris and Travis. Basically any question I have ever had with Vim, these two were able to answer them. But for times when they are not around I love using these sites:
- List of useful tips: http://rayninfo.co.uk/vimtips.html
- Wiki page of tips: http://vim.wikia.com/wiki/Main_Page
- Cheat sheet (PDF): http://www.sm.luth.se/csee/courses/smd/139/smd139_vi.pdf
- Color coded cheat sheet of keys and their commands: http://www.viemu.com/vi-vim-cheat-sheet.gif
This is a very short list because Vim is based on a few basic concepts and building on top of that. Once you get the basics, learning how to use buffers and macros gives you the ability to edit your files in any manner.
Coding Tip: Programming as a Game
I recently read a Wired article where people achieved success losing weight because Weight Watchers is basically an RPG. One game/exercise that I often do is to see how many lines of code or components I can write without any errors. It’s hard to quantify but my record so far as about 200 lines of Javascript/AJAX code. It was kind of cheating because I was basically re-using Javascript and backend PHP code that had been thoroughly tested. Overall, this is a pretty good method to increase the amount of code you can hold in your head and attempts to reduce the relying of debugging tools in favor of self/mental debugging.
Sopcast and TVAnts: Stream Live TV or Movies From Home
I’m a really big sports fan, especially soccer. Living in the United States, this means that most international games are always 7 or more hours earlier than usual, and sometimes, they don’t even broadcast locally.
Using Sopcast and TVAnts, I’m able to watch any game I want, when I want. Granted, this is streaming P2P video so it is not the best quality and due to the latency, images can get choppy. For popular content like the current Euro 2008 or most UEFA Champions League matches, speed and quality can rival that of Vimeo or Youtube.
After painstakingly getting Sopcast to work on my linux box, I found this really easy to use tutorial on installing both Sopcast and TVAnts:
http://simonsmess.blogspot.com/2007/11/watching-sopcast-tvants-on-ubuntu.html
For TVAnts, get a link from a website or open the program under wine, double click a channel and write down link from popup box. This will start the stream on your local computer where you can use VLC or other capable media programs to view that stream.
With Sopcast, the method to start the stream is very similar. You can download the actual program and run it under wine or use the command line version which also creates a stream from your local computer like TVAnts.
Now that you have a link and you are streaming, use your favorite media play to stream or record that link. My favorite, VLC, makes it fairly easy to open and save that link. To just open the link, VLC has an option under “File” >> “Open Network Stream”. To save the stream is the same except you specifiy where you want your stream to be saved.
In order to provide Tivo-like recording, I use my crontabs to start and stop the stream. Here is a pretty good tutorial on using crontabs. Of course it would be much easier to use MythTV if the content was available on your tv, but Sopcast and TVAnts provide a way to accomplish almost the same functionality with a more work.
Memcached Equals Time Saver
Memcached is a wonderful tool to offload database calls by storing the needed information in cache. One trick I’ve been using to increase productivity is that whenever I know I will be using complex or long running queries, I use a local instance of Memcached to cache the initial database calls. As I debug the output or tweak the logic, the average runtime of the script stays almost constant because the bulk of the processing, database calls, has been cached.