This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def test(a=0,b="salut",c=[],d=[]): | |
... a += 1 | |
... b += "!" | |
... c += [2] | |
... d = d + [42] | |
... print a, b, c, d | |
... | |
>>> test() | |
1 salut! [2] [42] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def current_exception_details(): | |
"""Retourne un tuple contenant les les informations sur l'exception | |
en cours de traitement | |
Retour : ( | |
Nom du fichier, | |
Ligne, | |
Nom de l'exception, | |
Type de l'exception, | |
Message de l'exception |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClosureIterator { | |
private static interface Iterator<T> { | |
T next(); | |
} | |
private static class Container<T> { | |
private T value; | |
public Container(T value) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
/** | |
* Slave task that allows for asynchronous operations based on a FIFO queue. | |
*/ | |
public class Async extends Thread { | |
private LinkedList<Runnable> tasks = new LinkedList<Runnable>(); | |
private boolean stop = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BitSet<T extends Enum<?>> { | |
private byte[] bytes; | |
@SafeVarargs | |
public BitSet(T... elements) { | |
bytes = new byte[elements.length / 8 + 1]; | |
} | |
private int bitMask(int ordinal) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# | |
# Generation config | |
# | |
PRINT_COLS = 8 | |
LETTERS_CHANGED = 2 | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lazy(fun): | |
class Memoizer(object): | |
def __init__(self, fun): | |
self.fun = fun | |
self.set = False | |
self.res = None | |
def __call__(self): | |
if not self.set: | |
self.set = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: Utf-8 -*- | |
import xml.etree.ElementTree as ET | |
def create_xml_tree(root, dict_tree): | |
# Node : recursively create tree nodes | |
if type(dict_tree) == dict: | |
for k, v in dict_tree.iteritems(): | |
create_xml_tree(ET.SubElement(root, k), v) | |
return root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Simple template system with plain JS objects, using CSS selectors | |
// Two versions : | |
// * JSON | |
// - based on JSON objects, each element is a property | |
// * JSON-ML : | |
// - inspired from the JSON-ML markup language (http://www.jsonml.org/) | |
// - each element is a list | |
// - element type can contains id and classes like the first version (so, not standard json-ml) | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspired from : http://www.sitepoint.com/multi-threading-javascript/ | |
longOperation: function (fn, initData, interval) { | |
var data = initData, busy = false; | |
var result = $q.defer(); | |
var taskId; | |
var task = function() { | |
if(!busy) { | |
busy = true; | |
var res = fn(data); | |
data = res.data; |
OlderNewer