Skip to content

Instantly share code, notes, and snippets.

@ksheedlo
ksheedlo / __init__.py
Last active June 8, 2016 19:14
Simple library set up for calling TISEAN programs as Python functions. I'm going to use this on the next chaos pset.
###############################################################################
#
# File: tizz/__init__.py
# Author: Ken Sheedlo
#
# TISEAN interface library for Python
#
###############################################################################
import numpy
@ksheedlo
ksheedlo / Output
Created March 5, 2013 20:16
Reasons to switch to Python 3
$ python look.py
File "look.py", line 3
ಠ_ಠ = 42
^
SyntaxError: invalid syntax
$ ./look.py
42
@ksheedlo
ksheedlo / decorators.py
Created December 3, 2012 18:25
Fun with Python decorators
HANDLERS = {}
def handler_decorator(*dargs, **dkwargs):
'''
This function is actually a decorator factory.
It makes decorators that take arguments.
'''
print "Ermuhgerd! Erm uh dehcruter!"
@ksheedlo
ksheedlo / introspect.py
Created November 3, 2012 05:06
Introspection for class discovery in Python
'''
Usage (from one directory up):
$ python -m introspection.introspect
'''
# The local package's name.
import introspection
import re
@ksheedlo
ksheedlo / lights.c
Created October 10, 2012 08:31
Solver code for a puzzle in Bloodshot Stronghold - Borderlands 2
#include<stdint.h>
#include<stdio.h>
#define MAX_LEVEL 15
int32_t search(int32_t state, int32_t l, int32_t p, int32_t w, int32_t level) {
const int32_t table[3][4] = {
/* Pattern of XOR operations for the lever */
{ 20, 3, 20, 3 },
/* Pattern of XOR operations for the switch */
@ksheedlo
ksheedlo / gist:3045659
Created July 4, 2012 06:07
Miller-Rabin primality in Python
import random
_rng = random.SystemRandom()
def modexp(base, exp, mod):
'''
Classic modular exponentiation by repeated squaring.
'''
acc = 1