Skip to content

Instantly share code, notes, and snippets.

View 4skl's full-sized avatar
Oh ! Hi, send me a message if u want, I'll be keen to work with you !

4skl

Oh ! Hi, send me a message if u want, I'll be keen to work with you !
  • 4skl
  • France
  • 09:29 (UTC +02:00)
View GitHub Profile
@Bamco
Bamco / permutations.ml
Created August 4, 2013 21:08
Ocaml list permutations
(* interleave 1 [2;3] = [ [1;2;3]; [2;1;3]; [2;3;1] ] *)
let rec interleave x lst =
match lst with
| [] -> [[x]]
| hd::tl -> (x::lst) :: (List.map (fun y -> hd::y) (interleave x tl))
(*permutations [1; 2; 3] = [[1; 2; 3]; [2; 1; 3]; [2; 3; 1]; [1; 3; 2]; [3; 1; 2]; [3; 2; 1]] *)
let rec permutations lst =
match lst with
| hd::tl -> List.concat (List.map (interleave hd) (permutations tl))
@glarrain
glarrain / gist:3982485
Created October 30, 2012 19:37
Decode session data, no matter what hashes say. It helps in some cases where the Session.get_decoded method returns an empty dictionary because it is "suspicious" of user-data tampering. Based on source code from the Django project.
import base64
import pickle
from django.contrib.sessions.models import Session
from django.utils.encoding import force_unicode
def decode_session_data(session_key):
"""Decode the data in a session object stored under ``session_key``.