Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / __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 / fortunes.txt
Created April 16, 2013 08:06
Fun with Linux programs
_____________________________________
/ You have the body of a 19 year old. \
| Please return it before it gets |
\ wrinkled. /
-------------------------------------
\ /\ ___ /\
\ // \/ \/ \\
(( O O ))
\\ / \ //
\/ | | \/
@ksheedlo
ksheedlo / brew doctor
Created May 20, 2013 06:47
haskell-platform failed to build on 10.8
$ brew doctor
Your system is ready to brew.
@ksheedlo
ksheedlo / error-message-minification-with-minerr.md
Last active December 21, 2015 03:29
Error Message Minification with MinErr

With the release of AngularJS 1.2.0rc1, the Angular team announced our new error message minification service, called MinErr (pronounced "miner"). MinErr provides more insight to developers about error conditions in their app, while also reducing code size. To ease the transition, let's take a detailed look at MinErr and try to answer any questions that might come up.

What is MinErr and why did you build it?

Angular has had some cryptic and confusing error messages in the past.

@ksheedlo
ksheedlo / bower.json
Last active December 31, 2015 05:19
HTML5 Drag n Drop
{
"name": "dnd-demo",
"version": "0.0.1",
"authors": [
"Ken Sheedlo <ovrkenthousand@gmail.com>"
],
"description": "HTML5 drag-n-drop table prototype",
"main": "index.js",
"license": "MIT",
"private": true,