Skip to content

Instantly share code, notes, and snippets.

@rollingstone
rollingstone / fcn_bench.py
Created March 15, 2016 15:27 — forked from mmmikael/fcn_bench.py
fcn benchmark
from keras.models import Sequential
from keras.layers.core import Permute
from keras.layers.convolutional import Convolution2D
from keras.layers.core import Activation
import theano
import theano.tensor as T
import datetime
import numpy as np
now = datetime.datetime.now
@rollingstone
rollingstone / hmm.py
Created May 13, 2016 11:32 — forked from jzelner/hmm.py
Example of the Forward-Backward algorithm implemented using Theano
#Forward-backward algorithm implementation in Theano,
#with example taken from Wikipedia:
#http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm
import theano
import theano.tensor as T
import numpy as np
#Set up vectors, etc to represent
#observations, indexes into the observation
import numpy as np
from scipy import linalg
from sklearn.utils import array2d, as_float_array
from sklearn.base import TransformerMixin, BaseEstimator
class ZCA(BaseEstimator, TransformerMixin):
def __init__(self, regularization=10**-5, copy=False):
self.regularization = regularization
@rollingstone
rollingstone / complex_radar_plot.py
Created September 25, 2016 16:15 — forked from kylerbrown/complex_radar_plot.py
Code for a complex radar plot
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns # improves plot aesthetics
def _invert(x, limits):
"""inverts a value x on a scale from
limits[0] to limits[1]"""
return limits[1] - (x - limits[0])
def _scale_data(data, ranges):
@rollingstone
rollingstone / keras_gensim_embeddings.py
Created May 23, 2017 23:14 — forked from codekansas/keras_gensim_embeddings.py
Using Word2Vec embeddings in Keras models
from __future__ import print_function
import json
import os
import numpy as np
from gensim.models import Word2Vec
from gensim.utils import simple_preprocess
from keras.engine import Input
from keras.layers import Embedding, merge
@rollingstone
rollingstone / regexnfaparser.py
Created August 25, 2017 16:24 — forked from taylor/regexnfaparser.py
python regex to (simple) NFA parsing code
"""
From: https://github.com/darius/sketchbook/blob/master/regex/integrated1.py
Integrate the right-to-left top-down operator-precedence parser with
the simplest terminating NFA code.
"""
def match(re, s): return run(prepare(re), s)
def run(states, s):
@rollingstone
rollingstone / repermute.py
Created October 22, 2017 20:32 — forked from mdeous/repermute.py
generate all possible permutations of a regex
# -*- coding: utf-8 -*-
#
# Used like this:
#
# from repermute import ipermute
#
# for s in ipermute('[A-Z]\d'):
# print s
#
# Almost all regular expression constructs are supported except for '*'
@rollingstone
rollingstone / sanic-websockets.py
Created February 5, 2020 05:03 — forked from ahopkins/# Sanic websocket feeds v2.md
Sanic based websocket pubsub feed
import json
import random
import string
from functools import partial
from sanic import Sanic
import aioredis
import asyncio
import websockets
@rollingstone
rollingstone / sha256.js
Created February 13, 2022 22:36 — forked from GaspardP/sha256.js
SHA-256 with Javascript and Web Crypto
// Computes the SHA-256 digest of a string with Web Crypto
// Source: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
function sha256(str) {
// Get the string as arraybuffer.
var buffer = new TextEncoder("utf-8").encode(str)
return crypto.subtle.digest("SHA-256", buffer).then(function(hash) {
return hex(hash)
})
}
@rollingstone
rollingstone / test.py
Created April 15, 2022 07:13 — forked from jd20/test.py
Testing PyAV encoding
import argparse
import av
import logging
import time
def parse_options(preset, tune, crf, x264_params, x265_params):
opts = {}
if preset:
opts['preset'] = preset