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.
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!
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
I’m not feeling awesome right now, but I still owe you a gist for the day. This one I did about a fortnight ago, it’s a circular buffer implementation.
Here’s the gist: https://gist.github.com/manchicken/6238117
Continue reading Gist of the Day: Circular Buffer
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.
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).
My spirit animal as an animated GIF – The Oatmeal.
(The Oatmeal, I love your stuff. If you don’t like me linking to your stuff please let me know and I won’t post it)
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
So, I thought I’d just do a quick and simple quicksort implementation for you today. It’s nothing fancy, and there are certainly faster ways to do this (not involving making new arrays and such), but this is pretty simple.
Here’s the Gist: https://gist.github.com/manchicken/6358106
Continue reading Gist of the Day: Quicksort
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