Skip to content

{ Category Archives } programming

Pipelines in Python

Generators (PEP 255 “Simple Generators”) and Coroutines (PEP 342 “Coroutines via Enhanced Generators”) are the cleanest way I’ve come across so far to implement the concept of a “pipeline” in Python. First approximation A pipeline is made of: a Producer, that generates data; many Stages, that receive data from the previous stage and send it to [...]

Tagged , , ,

Change engine to all tables in a MySQL database

Here is a simple shell script to change the engine of all the tables in a MySQL database: Just because, as usual, I keep forgetting these kind of things…

Tagged , , ,

hsenv

If you have never used hsenv before, you should. It’s basically the Haskell’s equivalent of Python’s virtualenv. You can find a tweaked version of hsenv here: I’ve relaxed some requirements in order to make it install on newer GHC releases. Finally, if when using you hit this error: Then, you have a problem with your [...]

Tagged , , , ,

Sudoku solver in Haskell

Recently, I’ve been challenged to write a Sudoku solver. Not knowing the rules and with only 30 minutes, I needed some help… So, in case someone asks me again, I’ve implemented the same algorithm in Haskell. I know that there are already a lot of other solutions, but, hey, it was fun!

Tagged ,

HSGrep benchmarking

Few days ago, I rewrote sgrep in Haskell. I was curious to know how it compares to grep in term of execution speed. In particular, I was interested to verify that hsgrep scales as O(log n), instead of O(n), with n being the size of the file analyzed. First of all, in order to have [...]

Tagged , ,

HSGrep: Sorted Grep in Haskell

As an exercise to learn Haskell, I wrote a specialized grep to work on sorted files. It uses binary search to scan a text file and print all the (consecutive) lines that start with a user defined string. My program is a rewrite of sgrep in Haskell: I called it HSGrep. Code is available on [...]

Tagged , ,

git pre-commit hook for python and javascript

Following a recent discussion on HN, I decided to share my own git pre-commit hook. It’s a work-in-progress, so you can find the most updated version here. To use it, just drop it in your .git/hooks directory. At every git commit, it will run pep8 and pyflakes on .py files, and gjslint on .js files.

Tagged , , , , , ,

Haskell and VIM

I had to tinker quite a bit before finding a decent configuration for vim to edit Haskell files. Here are the packages and config files I use: Haskell mode: interaction with Haddock, compiler integration, and other general settings. Indentation: proper source code indentation. More configs to enforce good style (no tabs, tabstops, etc.):  You can [...]

Tagged , ,

http client in haskell

To try to make sense of this, I decided to write a “simple” http client in Haskell in as many styles as I could think of: it’s a long time since I found so many new concepts while studying a new programming language…

Tagged , , ,

pylint.vim

vim + python + pylint is a powerful combination, especially when using this vim plugin. unfortunately, the script stopped working after a pylint upgrade: you can download the fixed version here! if interested, the patch looks like this:

Tagged , ,