Skip to content

Instantly share code, notes, and snippets.

@lbolla
lbolla / pylint.vim
Created August 25, 2011 10:43
pylint
" Vim compiler file for Python
" Compiler: Style checking tool for Python
" Maintainer: Oleksandr Tymoshenko <gonzo@univ.kiev.ua>
" Last Change: 2011 Aug 25
" Version: 0.5
" Contributors:
" Artur Wroblewski
" Menno
" Lorenzo Bolla
"
@lbolla
lbolla / haskell-.vimrc.vim
Created October 15, 2011 09:59
Haskell VIM files
" Add to .vimrc
" Need to have .vim/compiler/ghc.vim
augroup HSK
au Bufenter *.hs compiler ghc
autocmd FileType haskell setlocal formatoptions+=t
autocmd FileType haskell let b:ghc_staticoptions = '-Wall -Werror'
augroup END
@lbolla
lbolla / add_reviewer_bookmarklet.js
Created October 21, 2011 09:16
Add reviewer to Gerrit
javascript:(function() {var s=document.createElement('script'); s.src="https://raw.github.com/gist/1303423/4859b59a423612c90ec5b0c77591f984c4dfdd07/add_reviewers.js"; document.getElementsByTagName('head')[0].appendChild(s);})()
@lbolla
lbolla / taba.hs
Created January 15, 2012 17:46
There and Back Again
-- There and Back Again
-- http://www.brics.dk/RS/02/12/BRICS-RS-02-12.pdf
-- Fold a function over a sequence and the reverse of another sequence, in
-- just one passage.
taba :: ((t1, t2) -> t -> t) -> t -> [t1] -> [t2] -> t
taba f b xs ys =
let (r, _) = foldr (\x (r, y:ys) -> (f (x,y) r, ys))
(b, ys)
xs
@lbolla
lbolla / Sudoku.hs
Created February 27, 2012 17:23
Brute force Sudoku solver
module Main where
import Data.List (nubBy, concat, findIndices)
import Control.Monad (liftM2, forM, join, guard)
import Data.Maybe (catMaybes, fromMaybe)
import Debug.Trace
type Board = String
-- Some boards
@lbolla
lbolla / pipeline_1.py
Created April 20, 2012 12:34
Python pipelines
'''Pipeline
(yield) -> receiver
.send -> producer
'''
import time
N = 0
@lbolla
lbolla / Makefile
Created September 1, 2012 08:12
Warp vs. Yesod benchmark
GHC=ghc --make -O2 #-threaded
GHC_PROF=${GHC} -prof -auto-all
warp: warp.hs
${GHC} warp.hs
warp-prof: warp.hs
${GHC_PROF} warp.hs
yesod: yesod.hs
@lbolla
lbolla / README.md
Created October 3, 2012 10:05
Asynchronous programming in Tornado

Asynchronous programming with Tornado

Asynchronous programming can be tricky for beginners, therefore I think it's useful to iron some basic concepts to avoid common pitfalls.

For an explanation about generic asynchronous programming, I recommend you one of the [many][2] [resources][3] [online][4].

I will focus on solely on asynchronous programming in [Tornado][1]. From Tornado's homepage:

@lbolla
lbolla / futures_test.py
Last active April 24, 2023 17:59
Tornado and concurrent.futures
from concurrent.futures import ThreadPoolExecutor
from functools import partial, wraps
import time
import tornado.ioloop
import tornado.web
EXECUTOR = ThreadPoolExecutor(max_workers=4)
"""
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage.
Do not forget to replace YOURSERVER by the correct value.
Keep in mind that you need the *very latest* version of your web browser.
You also need to add Jacob Kristhammar's websocket implementation to Tornado:
Grab it here:
http://gist.github.com/526746
Or clone my fork of Tornado with websocket included:
http://github.com/pelletier/tornado
Oh and the Pub/Sub protocol is only available in Redis 2.0.0: