Skip to content

Instantly share code, notes, and snippets.

; ModuleID = 'test1.o'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
define i32 @main() {
entry:
%retval = alloca i32 ; <i32*> [#uses=2]
%z = alloca i32 ; <i32*> [#uses=2]
%y = alloca i32 ; <i32*> [#uses=1]
%x = alloca i32 ; <i32*> [#uses=2]
import matplotlib.pyplot as plt
def getFancyFig():
fig_width_pt = 240.0 # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27 # Convert pt to inch
golden_mean = (sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt # width in inches
fig_height = fig_width*golden_mean # height in inches
fig_size = [fig_width,fig_height]
params = {'backend': 'pdf',
@jasonmc
jasonmc / gist:989158
Created May 24, 2011 17:16
Python code for generating integer compositions. First algorithm thanks to Knuth 7.2.1.3
def compositions(t=2,s=2):
"""knuth 7.2.1.3"""
q = [0] * (t+1)
r = None
q[0] = s
while True:
yield q[:]
if q[0] == 0:
if r==t:
break
@jasonmc
jasonmc / bus.py
Created June 6, 2011 10:46
CLI script to get the Dublin Bus info for a stop
import urllib
import json
def main(location = "westland+row/00495"):
data = json.loads(urllib.urlopen("http://dublinbus-api.heroku.com/stops/%s"%location).read())['data'][0]
if data['active']:
for bus in data['buses']:
print bus['route'],'\t',bus['destination'],'\t',bus['time']
@jasonmc
jasonmc / git-redact
Created August 1, 2011 14:48
Place in PATH and can call 'git redact xyz' to remove all occurenences of xyz in repo. Watch out for cached copies though.
#!/bin/bash
git filter-branch -f --tree-filter "sed -i '' -e 's/$1/REDACTED/' $FILENAME" -- --all
@jasonmc
jasonmc / simulatedAnnealingCalc.py
Created August 19, 2011 19:23
Simulated annealing calculator
# Licensed under CRAPL - see http://matt.might.net/articles/crapl/CRAPL-LICENSE.txt
from math import exp
import matplotlib.pyplot as plt
def doplot(r,filename=None,lw=0.1,fancy=False):
fig = plt.figure()
ax = fig.add_subplot(111)
l = ax.plot(r)
plt.setp(l, color='k', linewidth=lw,aa=True)
@jasonmc
jasonmc / gist:1160951
Created August 21, 2011 18:23
Setting colors in matplotlib easily (can do white-on-black)
def set_foregroundcolor(ax, color):
'''For the specified axes, sets the color of the frame, major ticks,
tick labels, axis labels, title and legend
'''
for tl in ax.get_xticklines() + ax.get_yticklines():
tl.set_color(color)
for spine in ax.spines:
ax.spines[spine].set_edgecolor(color)
for tick in ax.xaxis.get_major_ticks():
tick.label1.set_color(color)
@jasonmc
jasonmc / twosComplement.py
Created September 13, 2011 19:24
Calculating twos complement
dSize = 8
twosC = lambda x: (x ^ (2**dSize -1))+1
print "Twos complement of 11 is:", twosC(11), "(" + bin(twosC(11)) + ")"
@jasonmc
jasonmc / gist:1335497
Created November 3, 2011 01:22
Accessing overloaded ()
#include <iostream>
using namespace std;
class Test {
public:
void operator()(int a) {
cout << a << endl;
}
@jasonmc
jasonmc / onchangerecur
Created November 17, 2011 20:12
A script that uses inotiftwait to look for changes in all files with given extension, and run specifed command. Useful for compiling LaTeX.
onchangerecur . 'pdflatex -interaction batchmode thesis.tex' .tex