For my startup project darticle, we have several "jobs" which need to be taken care of outside of standard web page serving, including e-mailing and web scraping. For scalability, these jobs are handled asynchronously and concurrently, with the goal of the job queue being able to scale across various servers. Here I will write about darticle's solution for implementing such a job management system with CouchDB.
One of the side effects of needing a temporary directory is needing to clean up after yourself. In my case, I extract a plugin into its own temporary directory (though it's currently not sandboxed) and load assemblies (kinda like ELF files) from that directory. When my plugin objects are disposed of (IDisposable and all that), the directory needs to be deleted.
Want to remove the sound tracks from your video files? Download script here. Drag-and-drop video files into strip-sound.bat.
For rationale and other details, read more.
I'm going to begin my adventure into polyphasic sleep. In particular, I'm going to use the three-nap Everyman cycle. This blog will be a log of this adventure.
The three hour sleep is from 22:00 to 01:00. The three naps are at 06:30, 11:30, 16:30.
Hopefully I can adhere to this schedule. On school days, 06:30 is bus time, 11:30 is around lunch time, and 16:30 is after school and sometimes car time.
Entries for the USACO contests require a template header and some boilerplate code. To make things easier, I put boilerplate generation into a little script.
#!/bin/sh FILENAME=$1 TASKNAME=$(echo "$1" | sed -e 's/\..*$//') TEMPLATENAME=$(echo "$1" | sed -e 's/^.*\.//') sed -e 's/#TASKNAME#/'"$TASKNAME/" < template."$TEMPLATENAME" > "$FILENAME"
Template files (e.g. template.c) look like this:
/* ID: your_id_here LANG: C TASK: #TASKNAME# */ #define PROG "#TASKNAME#" #include <stdio.h> int main() { FILE *fin = fopen(PROG ".in", "r"); FILE *fout = fopen(PROG ".out", "w"); return 0; }
Just give the Bash script the name of the file you need and it will make the file with the appropriate language (based off the extension given) and task name.
Yesterday, our math teacher announced there was to be held a county-sponsored math competition the following day. Long story short, I had a day to prepare for the competition. Sadly, I didn't know what to prepare for until the following day (that is, the day of the test). I was given a sample test and worked those math problems.
One of the problems was of the following sort:
Give the first 4 digits of 20092009.
This is a crazy problem, and I was sure there was some stupid math trick which wasn't really math to accomplish this.
Update: Twitter changed its authentication scheme so this plugin no longer works.
A while ago, I wondered why I had a Twitter account. I didn't use it, and everything interesting I was doing I put in my away message in irssi (with, in addition to IRC, my IM accounts, thanks to BitlBee).
So I thought, why not Twitter my away messages? I made a Perl script for irssi to do just that.
I've found that when beginning to write a tokenizer from scratch, it's best to lay out the definitions of your token types. It doesn't have to be in some magic format; just something you can understand will work.
For each token type, create a function to read that token and no more, and return that token as an object. (Be sure to add error handling and such.) Different types of tokens should use the same base class. (You can use an enum or subclasses. I chose an enum for its simplicity.) As for the name, Read<em>Type</em> is what I chose, as it does exactly that: reads a number, string, etc. from the input.
Then have a function to figure out what token follows, and have it return the token using the function you created earlier. ReadToken is a descriptive name.
It's a simple while loop to read in multiple tokens. Be sure to skip whitespace between tokens if it's unimportant. Naturally, this goes in a function called Tokenize or similar.
And now you have your tokenizer. Simple, wasn't it?