Skip to content

Instantly share code, notes, and snippets.

on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
tell application "Google Chrome"
@shurain
shurain / conv_deconv_vae.py
Last active August 29, 2015 14:15 — forked from kastnerkyle/conv_deconv_vae.py
conv_deconv_vae.py
# Alec Radford, Indico, Kyle Kastner
# License: MIT
"""
Convolutional VAE in a single file.
Bringing in code from IndicoDataSolutions and Alec Radford (NewMu)
Additionally converted to use default conv2d interface instead of explicit cuDNN
"""
import theano
import theano.tensor as T
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
@shurain
shurain / dnn.py
Last active August 29, 2015 14:12 — forked from syhw/dnn.py
A deep neural network with or w/o dropout in one file.
"""
A deep neural network with or w/o dropout in one file.
License: Do What The Fuck You Want to Public License http://www.wtfpl.net/
"""
import numpy, theano, sys, math
from theano import tensor as T
from theano import shared
from theano.tensor.shared_randomstreams import RandomStreams
@shurain
shurain / mutual_info.py
Last active August 29, 2015 14:06 — forked from GaelVaroquaux/mutual_info.py
Non-parametric computation of entropy and mutual-information
'''
Non-parametric computation of entropy and mutual-information
Adapted by G Varoquaux for code created by R Brette, itself
from several papers (see in the code).
These computations rely on nearest-neighbor statistics
'''
import numpy as np
@shurain
shurain / README.md
Last active August 29, 2015 14:06 — forked from takluyver/README.md
Flatten notebooks for git diff

Copy nbflatten.py to somewhere on $PATH. Then, in the root of a git repository, run these commands:

echo "*.ipynb diff=ipynb" >> .gitattributes 
git config diff.ipynb.textconv nbflatten.py

When you change a notebook and run git diff, you'll see the diff of flattened, simplified notebooks, rather than the full JSON. This does lose some information (metadata, non-text output), but it makes it easier to see simple changes in the notebook.

This doesn't help with merging conflicting changes in notebooks. For that, see nbdiff.org.

@shurain
shurain / 538.json
Created August 12, 2014 06:15 — forked from CamDavidsonPilon/538.json
Use the two files below to mimic graphs on 538. www.dataorigami.net/blogs/fivethirtyeight-mpl
{
"lines.linewidth": 2.0,
"examples.download": true,
"patch.linewidth": 0.5,
"legend.fancybox": true,
"axes.color_cycle": [
"#30a2da",
"#fc4f30",
"#e5ae38",
"#6d904f",
@shurain
shurain / gist:10222709
Last active August 29, 2015 13:58 — forked from mitsuhiko/gist:10130454
Quick and dirty demonstration of CVE-2014-0160 by
#!/usr/bin/env python
# Quick and dirty demonstration of CVE-2014-0160 by
# Jared Stafford (jspenguin@jspenguin.org)
# Modified so that it finds cookies
import sys
import struct
import socket
import time
import select
@shurain
shurain / whiteboardCleaner.md
Last active December 11, 2015 04:42 — forked from lelandbatey/whiteboardCleaner.md
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@shurain
shurain / gist:9739449
Last active August 29, 2015 13:57 — forked from enygma/gist:1413370
Simple RSS feed creation for @PHPQuickFix
<?php
$jsonCacheFile = './quickfix.json';
$gimmieFeed = 'https://gimmebar.com/api/v0/public/assets/phpquickfix';
$wgetCmd = 'wget -O'.$jsonCacheFile.' '.$gimmieFeed;
// look for the cache file
if(!is_file($jsonCacheFile) || (is_file($jsonCacheFile) && filemtime($jsonCacheFile)<strtotime('-1 minute')) ){
// fetch the latest content from gimmiebar
exec($wgetCmd);
@shurain
shurain / matrix_sketch.py
Created November 6, 2013 05:09 — forked from mblondel/matrix_sketch.py
Frequent directions algorithm for matrix sketching.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
from scipy.linalg import svd
def frequent_directions(A, ell, verbose=False):
"""
Return the sketch of matrix A.