Gist of the Day: Perl Closure Extravaganza!

Hey all, so I’ve been asked to do something a little more in-depth, and I’ve been given no requests, so I picked closures in Perl.

About Closures

A closure is a function which was created dynamically inside of another function. In Perl (among other languages), these are sometimes referred to as anonymous subroutines. In Perl, all closures are anonymous subroutines, but not all anonymous subroutines are closures. The key differentiating feature is scope: a closure has access to lexically-scoped variables within a containing subroutine, whereas an anonymous subroutine is not necessarily even inside of a function. Continue reading Gist of the Day: Perl Closure Extravaganza!

Gist of the Day: Self-Balancing Binary Tree in Python

So I’m trying to learn Python, as you know. I’m also trying to practice algorithms a bit more. Today you get a self-balancing binary tree in Python.

I’ve used unittest in order to prove the implementation, too.

Here’s the Gist: https://gist.github.com/manchicken/6391864
Continue reading Gist of the Day: Self-Balancing Binary Tree in Python

Neat Perly Stuff

So, it’s been a while since I looked at the perldelta (yes, I know that makes me a terrible human being). I found some neat toys to play with, I thought you might like to see. It’s just a simple script so far, but I’m going to add features as I find them. Check it out.

https://github.com/manchicken/gist_per_day/blob/master/perl_510_play.pl

So far I have only toyed with state variables and named capture buffers in regular expressions, but there’s a whole bunch of neat stuff.

Please also note that the FuckDiabetes website code is already on my GitHub, and it is already using a whole bunch of new Perl ideas, such as Mojolicious, Moose, and Mongoose (MongoDB and Moose together kinda like an ORM). You can find FuckDiabetes’ code here: https://github.com/manchicken/FuckDiabetes (please note that FuckDiabetes is not yet live).

Gist of the Day: Threading in Python

So, I’m trying to learn Python better. Here’s me just doing a simple threading exercise with an anonymous function in Python. I am imitating a Perl Gist I did before with the exact same logic.

Here’s the Gist: https://gist.github.com/manchicken/6369630
Continue reading Gist of the Day: Threading in Python

Gist of the Day: Simple Threading in Perl

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:

  1. The value so far
  2. N
  3. 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

Gist of the Day: Mounting a Remote Share on OSX Using Obj-C and AppleScript

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

Gist of the Day: Map-Reduce in MongoDB

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