Skip to content

Instantly share code, notes, and snippets.

bool shit = True; // shit happens
@MachineCharmer
MachineCharmer / float_rng.cs
Created April 26, 2011 07:40
float random number generator c#
static Random random = new Random();
public double GetRandomNumber(double minimum, double maximum)
{
return random.NextDouble() * (maximum - minimum) + minimum;
}
//copied from:http://stackoverflow.com/questions/1064901/random-number-between-2-double-numbers/1064907#1064907
@MachineCharmer
MachineCharmer / start_func_in_thread.cs
Created April 25, 2011 11:55
run function in new thread
// copied from http://www.albahari.com/threading/
static void Main()
{
Thread t = new Thread ( () => Print ("Hello from t!") );
t.Start();
}
static void Print (string message)
{
@MachineCharmer
MachineCharmer / pimp.py
Created March 11, 2011 08:52
Pimp my Interactive Interpreter
#copied shamelessly from http://jasonmbaker.com/pimp-my-interactive-interpreter
import atexit
import os
import readline
import rlcompleter
import sys
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
readline.read_history_file(histfile)
@MachineCharmer
MachineCharmer / cnk.py
Created March 10, 2011 12:49 — forked from ikbear/cnk.py
function to calculate number of combinations
import operator
def c(n, k):
k = min(k,n-k) # using C(n,k) = C(n,n-k)
return (reduce(operator.mul, range(n-k+1, n+1)) /
reduce(operator.mul, range(1, k+1)))
@MachineCharmer
MachineCharmer / sage_graph_editor_usage.py
Created March 8, 2011 16:13
sage graph editor usage
g = Graph({0:[1,2],2:[1]})
graph_editor(g)