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).
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
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