Skip to content

Instantly share code, notes, and snippets.

@GM3D
GM3D / gist:7e838695f4f8f09978e5
Created July 19, 2014 06:42
Test run result of ex-3.15
n = 0
n = 1
1 initial orders were sortable within 0 ops.
n = 2
1 initial orders were sortable within 0 ops.
2 initial orders were sortable within 1 ops.
n = 3
1 initial orders were sortable within 0 ops.
4 initial orders were sortable within 1 ops.
6 initial orders were sortable within 2 ops.
import copy
import math
import random
def random_x():
return 2*random.randint(0, 1) - 1
def modify(x):
i = random.randint(0, 2)
xr = copy.copy(x)
@GM3D
GM3D / theano_scan_example2.py
Last active December 7, 2015 15:21
Theano simple implementation of exmaple 1 in the MCMC book
#!/usr/bin/python3
'''Theano simple implementation of exmaple 1 in the MCMC book,
the same progrm with
example1.py (https://gist.github.com/GM3D/51965c9e6de5456971b5).
without shared variable.'''
from __future__ import print_function
import numpy as np
import theano
from theano.ifelse import ifelse
#!/usr/bin/python3
import numpy as np
from numpy import random
N = 10
size = [N, N]
theta = 0.42
n_steps = 1000000
x = 2 * random.random_integers(0, 1, size=size) - 1
@GM3D
GM3D / pdf-to-png.sh
Last active December 8, 2016 11:52
shell script to convert a multi-page pdf to separate png images.
#!/bin/bash
fbody="$(basename "$1" .pdf)"
outfile="$(echo $fbody | sed -s s/-$//)"-p.png
convert -type Grayscale -density 600 -resample 100 -antialias "${fbody}.pdf" "$outfile"
from sympy import sqrt
N = 15
a = [[]]*N
for n in range(N):
a[n] = [0]*(n+1)
if n == 0:
a[0][0] = 1
else:
for l in range(n + 1):
@GM3D
GM3D / exercise-I-2-2.py
Last active October 2, 2017 07:59
Coursera Modular forms 2017 exercise I-2-2
#!/usr/bin/python3
from math import sqrt, factorial
from operator import mul
def binomial(n, k):
return factorial(n)/(factorial(n-k) * factorial(k))
def dot_prod(a, b):
return sum(map(mul, a, b))
@GM3D
GM3D / simplefuzzer3.py
Created November 14, 2013 08:09
A simple fuzzer based on Charlie Miller's "Babysitting an Army of Monkeys". Adjusted for Udacity CS258 PS4 homework.
#!/usr/bin/python
file_list = ["2010820135318.xls",
"tax__down_kyuyoido_rei.xls",
"toku-kirikae.xls",
"44hp.xls",
"tool_1_3.xls"]
apps = ["/usr/bin/gnumeric"]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.