Skip to content

Instantly share code, notes, and snippets.

View torbjo's full-sized avatar

Torkel Bjørnson-Langen torbjo

View GitHub Profile
#!/bin/bash -e
pkglst=$(pip list --user --outdated --format=freeze | cut -d= -f1)
if [ "$pkglst" = "" ]; then
echo "All pip packages is up to date. Nothing to do."
exit
fi
echo -ne "OUTDATED PIP PACKAGES:\n "
@torbjo
torbjo / split_n.py
Created July 5, 2018 12:33
Split list/sequence in cunks of N elements
def split_n (seq, n=1, allow_partial=True):
if not allow_partial and (len(seq) % n != 0): raise RuntimeError()
return [seq[i:i+n] for i in range(0,len(seq),n)]
"""
>>> print (split_n ('abcdefghijklmnopqrstuvwxy', 4))
['abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'y']
"""
@torbjo
torbjo / gist:d2826e40621fc9b5a6d624fde43ac7f4
Created May 27, 2017 15:54
Auto-reload browser window when files changes
$ apt-get install xdotool entr
$ find -name \*.css -or -name \*.html | entr -p xdotool key --window $(xdotool selectwindow) F5
@torbjo
torbjo / null.cc
Created December 18, 2016 15:15
Funny definition of NULL
#ifndef NULL
const int NULL =
!! ! ! ! ! !
! ! ! ! ! ! !
! !! ! ! ! !
! ! !!!!!! !!!!! !!!!!1;
#endif
@torbjo
torbjo / glitter-0.1.7-python3.patch
Created November 20, 2016 12:39
Python 3 patch for glitter-0.1.7
diff -ur glitter-0.1.7/glitter/contexts/textures.py glitter-0.1.7-python3/glitter/contexts/textures.py
--- glitter-0.1.7/glitter/contexts/textures.py 2014-04-11 11:15:21.000000000 +0200
+++ glitter-0.1.7-python3/glitter/contexts/textures.py 2016-11-20 13:15:18.448297416 +0100
@@ -10,12 +10,6 @@
from glitter.utils import BindableObject, GlitterError
from glitter.contexts.proxies import BindingProxy
-try:
- next
-except NameError:
@torbjo
torbjo / deck_of_cards.py
Created November 20, 2016 12:02
Cartesian product
import random
def cartesian_product (seq1, seq2):
return [a+b for a in seq1 for b in seq2]
# A deck of cards
deck = cartesian_product ('♠♥♦♣', list('123456789') + ['10'] + list('JQK'))
def shuffle_cards ():
random.shuffle (deck)
// Built-in Higher Order Functions for Array:
// map, filter, forEach, some, every, reduce
// The Emperor’s New Closure: FP in Javascript
// https://www.youtube.com/watch?v=a6azjixVy2g
l = [1,2,3,4,5]
function is_even(n) { return n%2==0; }; // predicate
function larger_than(n) { return function(m) { return m > n; } };
l.reduce(function (a,b) { return a+b; }); // sum(l)