Skip to content

Instantly share code, notes, and snippets.

View jbpotonnier's full-sized avatar

Jean-Baptiste Potonnier jbpotonnier

View GitHub Profile
@jbpotonnier
jbpotonnier / .gitignore
Created February 16, 2012 19:53
[Flask] Routing with class
bin
include
lib
local
*.swp
*.pyc
@jbpotonnier
jbpotonnier / hxt.markdown
Created February 24, 2012 14:18
Transform XML document using Haskell and XPath

I'm using HXT to transform a XML into another XML document. Selecting some nodes using XPath.

Here I want to collect all the authors in a new authors node.

Input document :

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
    <book category="COOKING">
        <title lang="en">Everyday Italian</title>
@jbpotonnier
jbpotonnier / facture.hs
Created February 29, 2012 11:02
Try to undersdand Haskell arrows
import Control.Arrow
facture :: Double -> String
facture = (* tjm)
>>>
id &&& (* tva) &&& (* (1 + tva))
>>>
show *** show *** show
>>>
@jbpotonnier
jbpotonnier / .gitignore
Created March 27, 2012 21:21
Try implementing a FSM
*~
.#*
\#*\#
@jbpotonnier
jbpotonnier / .gitignore
Created April 29, 2012 21:50
Play with Scotty web framework
.hsenv
@jbpotonnier
jbpotonnier / faces.py
Created May 15, 2012 22:19
Face recognition using OpenCV
import cv
class Detector(object):
def __init__(self, haar_file):
self.haar = cv.Load(haar_file)
self.storage = cv.CreateMemStorage()
def detect(self, image):
# parameters for fast detection
@jbpotonnier
jbpotonnier / map.hs
Created June 4, 2012 21:46
map is just fold, or is it the other way around :P Is fold enough to have map, filter, and recursion?
foldlmap :: (a -> b) -> [a] -> [b]
foldlmap f = foldl (\ a b -> a ++ [f b]) []
foldrmap :: (a -> b) -> [a] -> [b]
foldrmap f = foldr (\ a b -> (f a) : b) []
main :: IO ()
main = do
@jbpotonnier
jbpotonnier / model.py
Created June 4, 2012 21:50
Very basic json validation (you more likely want something like kwalify or WTForm)
from exceptions import Exception
def is_valid(model, instance):
missing_fields = set(model) - set(instance)
if missing_fields:
raise MissingFields(missing_fields)
missing_types = set(instance) - set(model)
if missing_types:
raise MissingTypes(missing_types)
type_errors = [(k, model[k], type(v)) for (k, v) in instance.items() if type(v) is not model[k]]
@jbpotonnier
jbpotonnier / .gitignore
Created June 5, 2012 21:10
Paths in ul-li
bin
local
include
lib
man
.Python
*.pyc
*.swp
@jbpotonnier
jbpotonnier / grep_gist.rb
Created June 14, 2012 23:14
Grep in gist description and display url
require 'net/http'
require 'uri'
require 'json'
def github(*list)
URI('https://api.github.com/' + list.join('/'))
end
def get(uri)
request = Net::HTTP::Get.new uri.request_uri