Skip to content

Instantly share code, notes, and snippets.

View cslarsen's full-sized avatar

Christian Stigen Larsen cslarsen

View GitHub Profile
@slode
slode / pprint_cmd.py
Last active September 16, 2016 08:47
def print_cmd(command, line_length=80, indent=" "):
import sys, textwrap
lines = textwrap.wrap(
command,
width=line_length,
subsequent_indent=" \\\n" + indent,
break_long_words=False,
break_on_hyphens=False)
for line in lines:
@floer32
floer32 / tupperware.py
Last active September 26, 2022 12:13
recursively convert nested dicts to nested namedtuples, giving you something like immutable object literals
from UserDict import IterableUserDict
import collections
__author__ = 'github.com/hangtwenty'
def tupperware(mapping):
""" Convert mappings to 'tupperwares' recursively.
@kohlmeier
kohlmeier / ka_bnet_numpy.py
Created March 26, 2012 21:59
Bayes net example in Python with Khan Academy data
#!/usr/bin/env python
from numpy import asmatrix, asarray, ones, zeros, mean, sum, arange, prod, dot, loadtxt
from numpy.random import random, randint
import pickle
MISSING_VALUE = -1 # a constant I will use to denote missing integer values
def impute_hidden_node(E, I, theta, sample_hidden):
@cslarsen
cslarsen / revlink.c
Created June 30, 2010 00:39
Reverse singly linked list in C
@cslarsen
cslarsen / permut.cpp
Last active September 5, 2015 07:35
Permutations in C++
/*
* Print all permutations of string ``s´´. (C++)
*
* Solved as a counting problem and coded in a hurry.
*
* A more elegant and recursive solution:
* http://nicolas-lara.blogspot.com/2009/01/permutations.html
*/
#include <stdio.h>