Skip to content

Instantly share code, notes, and snippets.

@mdamien
mdamien / gist:9399963
Created March 6, 2014 21:22
Quick and Dirty list section header for Android
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:clickable="false"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<View
android:id="@+id/item_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
@mdamien
mdamien / comb.py
Last active August 29, 2015 14:00
the limit
def cross(X,Y):
if len(X) == 0:
for y in Y:
yield y
for x in X:
for y in Y:
yield (x,y)
def combination(n):
@mdamien
mdamien / rainbow.js
Created April 29, 2014 20:04
Rainbow
function rainbow(step) {
var r, g, b;
var h = step / 70;
var i = ~~(h * 6);
var f = h * 6 - i;
var q = 1 - f;
switch (i % 6) {
case 0:
r = 1, g = f, b = 0;
break;
@mdamien
mdamien / dico.py
Created May 13, 2014 18:55
Basic dictionnary with WordNet
defs = {}
for i, line in enumerate(open('data.noun')):
if not line.startswith('0'):
continue
splits = line.split(' ')
word = splits[4]
seps = line.split('|')
bla = seps[1].split(';')
definition = bla[0]
@mdamien
mdamien / a_little_experiment.md
Last active August 29, 2015 14:01
Direct circular dependencies in the dictionnary

Because every word in a dictionnary is referenced by another word, there must be a lot of circular dependency

Example:

  • Definition of the: denoting one or more people or things already mentioned or assumed to be common knowledge
  • Definition of one: the lowest cardinal number; half of two; 1.

Using the Wordnet dictionnary, I looked for circular dependency. But I found so many direct dependency, I'm now looking for a better dictionnary (Wiktionnary most probably).

So, here is the result of the direct dependency lookup and the script to obtain the result.

@mdamien
mdamien / cookies.py
Last active August 29, 2015 14:07
atelier python
# https://docs.python.org/3.4/library/turtle.html
from turtle import *
import random
def draw_cookie(x, y):
penup()
goto(x,y)
pendown()
radius = random.randint(100,200)
col = random.choice(['#CC6600','#FFCD82','#8F4700'])
@mdamien
mdamien / match.py
Created December 20, 2014 11:10
pattern matching
def iterate_by_chunk(word, chunk_length):
i = 0
while i < len(word):
yield word[i:i+chunk_length]
i += chunk_length
def check(word, pattern, len_pattern_word, i_offset):
"""check if the word match the pattern"""
pattern_length = len(pattern)*len_pattern_word

given n, print all the combinations of 0...(n-1) of length n

example

n = 2

00
01
10

11

@mdamien
mdamien / jam.py
Last active August 29, 2015 14:12
#https://code.google.com/codejam/contest/7214486/dashboard
from collections import deque
from itertools import combinations
class Matrix:
@staticmethod
def from_string(M):
return Matrix([list(x.strip()) for x in M.split('\n')])
def __init__(self,M):
from pprint import pprint as pp
from collections import deque
def find_bridge_bf(nodes, edges, a, b):
"""
Simple brute-force bridge finding
For each edge, explore nodes from *a* and try to reach b without using the edge
If it can't reach the *b*, it was a bridge
"""
for edge in edges: