So today’s gist is a simple example of how to do two different things with two separate threads. Threading in Perl is misunderstood and often belittled, but it’s pretty straight-forward. The #1 problem that I think people encounter when threading in Perl is that they are using non-thread-safe code. If you’re using a CPAN module, you need to make sure you evaluate it for thread-safety prior to running it with threads (and if it’s using XS, it likely isn’t).
Anyway, this gist takes a function which crunches a set using a calculation routine. The calculation routine takes three parameters:
- The value so far
- And the next value in the set
From there, the calculation routine performs the appropriate action on the next value in the set – given the prior value and the value of N – and then returns the result.
Here’s the Gist: https://gist.github.com/manchicken/6349415
Way back when, I used to work on a Mac in a mostly Windows shop. People would send me windows network paths and expect me to be able to open them. I had to write a program to handle this stuff, and I thought this was a neat portion of that program.
Please note: This code was ripped out of its program, and therefore probably won’t work right away, though I think it’d be mostly portable. Check it out!
Here’s the Gist: https://gist.github.com/manchicken/6337966
This is assuming the previous Gist seen here, as well as the CSV file seen here.
Once you have Mongo loaded with this info, this MongoDB Script here will create an output table counting the first letter of the first name of all entries in the data loaded via CSV. It’s not terribly sexy, but it is kinda neat.
Here’s the Gist: https://gist.github.com/manchicken/6331238
This little script just takes your CSV file and sticks it into MongoDB. There’s a lot of output you might want to remove if you were to use it for a big file.
I wrote this mainly to help me as I get ready to experiment with some of this map-reduce stuff in MongoDB.
Here’s the Gist: https://gist.github.com/manchicken/6308596
So today you’re in for a treat! I’m not just doing the one gist, but I’m also sharing my lefty mouse switcher script for Windows environments. Check it out!
Here’s the Gist: https://gist.github.com/manchicken/6308171
As I do my gists I will play with new things. For tomorrow: a Python script which loads a CSV file into MongoDB. The day after the goal is to come up with a map-reduce for that.
I sincerely invite the (maybe) one person who is reading this to suggest some ideas for gists. Remember, keep it small.
In all of the picking up and learning of new things I’ve been doing lately, I’ve decided to make a Gist per day for 30 days. This won’t be super-awesome or innovative, but these are just little brain teasers for me to do every day.
Feel free to follow me as I go along. If you have any requests or suggestions, please feel free to jump in!
This is a simple Perl module to parse the /etc/lsb-release file. It’s nothing too fancy, but it has been useful from time to time.
Here’s the gist: https://gist.github.com/manchicken/6300554