Skip to content

Instantly share code, notes, and snippets.

View jbpotonnier's full-sized avatar

Jean-Baptiste Potonnier jbpotonnier

View GitHub Profile
@jbpotonnier
jbpotonnier / gtranslate.py
Created February 12, 2011 18:56
Translate between french and english using google api
# -*- coding: iso-8859-15 -*-
import Tkinter as tkinter
import urllib2, urllib
import json
TRANSLATE_URL = 'http://ajax.googleapis.com/ajax/services/language/translate'
TO_ENGLISH = 'fr|en'
TO_FRENCH = 'en|fr'
@jbpotonnier
jbpotonnier / reversi.hs
Created February 12, 2011 19:00
Reversi in Haskell. There is a bug in negamax, it's working, but the program should be stronger ;)
import Data.Array (Array, array, (//), (!), assocs, elems)
import Data.List (sortBy, groupBy, group)
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import Control.Monad (forever, when)
import Data.Maybe (isJust, isNothing)
import Data.Ord (comparing)
data Player = Black | White deriving (Show, Eq)
@jbpotonnier
jbpotonnier / ListZipper.hs
Created February 12, 2011 19:02
Playing with zipper, witch is a new concept for me
module ListZipper (
focused, focusedIndex,setFocusedIndex, setUnfocused,
forward, backward,
append,
toList, fromList
)
where
type Zipper a = ([a], [a])
@jbpotonnier
jbpotonnier / trie.hs
Created February 12, 2011 19:07
Tries
import Data.List (insertBy)
import Data.Ord (comparing)
data Trie = Trie {final :: Bool, children::[(Char,Trie)]}
deriving Show
empty :: Trie
empty = Trie {final=False, children=[]}
@jbpotonnier
jbpotonnier / Utils.hs
Created February 12, 2011 19:09
sokoban game. The maps can be downloaded from http://www.ne.jp/asahi/ai/yoshio/sokoban/auto52/index.html
module Utils where
import Data.Array (Ix, Array, assocs)
makeRows :: Int -> [a] -> [[a]]
makeRows _ [] = []
makeRows len elts =
(take len elts) : makeRows len (drop len elts)
@jbpotonnier
jbpotonnier / diffc.scm
Created February 19, 2011 20:33
Colorize unified diff output
(require-extension ansi-escape-sequences)
(require-extension srfi-13)
(require-extension extras)
(define (colorize txt)
(set-text
(cond
((string-prefix? "---" txt) '(bold))
((string-prefix? "+++" txt) '(bold))
((string-prefix? "-" txt) '(fg-red ))
@jbpotonnier
jbpotonnier / othelllo.ml
Created October 6, 2011 18:20
othello in ocaml
type player = | Black | White
type cell = | Cell of player | Empty
type board = (cell array) array
exception Invalid_position_exception of (int * int)
let opponent = function | Black -> White | White -> Black
let init_board () : board =
@jbpotonnier
jbpotonnier / GroupBy.hs
Created October 24, 2011 21:38
groupBy in Erlang and Haskell
module GroupBy where
import Data.Map (Map)
import qualified Data.Map as Map
groupBy :: Ord b => (a -> b) -> [a] -> Map b [a]
groupBy f = foldr (\ v -> Map.insertWith (++) (f v) [v]) Map.empty
groupBy' :: Ord b => (a -> b) -> [a] -> Map b [a]
@jbpotonnier
jbpotonnier / .gitignore
Created November 23, 2011 13:06
Introduction à Haskell
\#*\#
.*
@jbpotonnier
jbpotonnier / nimportequoi.py
Created December 8, 2011 16:10
fun avec bottle, pystache et ... redis
from bottle import Bottle
import bottle
import pystache
import redis
import json
app = Bottle()
redisse = redis.Redis()
def mustache(template, context):