Skip to content

Instantly share code, notes, and snippets.

View andreabedini's full-sized avatar
☺️

Andrea Bedini andreabedini

☺️
View GitHub Profile
"""
Elias Omega code in Python
http://en.wikipedia.org/wiki/Elias_omega_coding
Peter Elias, "Universal codeword sets and representations of the integers", IEEE Trans. Information Theory 21(2):194-203, Mar 1975.
Also known as the log* (or "logstar") code in Rohan Baxter's 1996 PhD thesis.
Type 'python EliasOmega.py' to run the tests.
"""
@HeinrichApfelmus
HeinrichApfelmus / RandomAccessParser.hs
Last active March 21, 2020 13:11
Parsing a random-access format into a pure data structure. Parsing will be lazy: parts of the data structure will be parsed on demand.
import Data.Word
import qualified Data.ByteString as B
type ByteString = B.ByteString
data Tree = Leaf [Word8] | Branch Tree Tree deriving (Eq,Show)
parse :: ByteString -> Tree
parse xs = case view xs of
Cons 0 xs -> case view xs of
Cons length xs -> Leaf . B.unpack $ B.take (fromIntegral . toInteger $ length) xs
/** @jsx React.DOM */
var MyComponent = React.createClass({
getInitialState: function() {
// set up the initial state. used for "logical" initialization code
return {perMinute: '-', perDay: '-'};
},
componentDidMount: function() {
// fired only once, when the component is added to the DOM
// used for initialization code that has "side effects" i.e. i/o, jquery plugins, etc
var socket = io.connect(this.props.url);
/** @jsx React.DOM */
var MyRootComponent = React.createClass({
getInitialState: function() {
return {perMinute: '-', perDay: '-'};
},
componentDidMount: function() {
var socket = io.connect(this.props.url);
socket.on('business.clickout', this.setState.bind(this));
},
render: function() {
/*
* call-seq:
* Rugged::Repository.new(name, options = {}) -> repository
*
* Open a Git repository with the given +name+ and return a +Repository+ object
* representing it.
*
*/
static VALUE rb_git_repo_new(int argc, VALUE *argv, VALUE klass)
{
@creationix
creationix / jsonparse.js
Last active May 10, 2024 14:36
A streaming JSON parser as an embeddable state machine.
// A streaming byte oriented JSON parser. Feed it a single byte at a time and
// it will emit complete objects as it comes across them. Whitespace within and
// between objects is ignored. This means it can parse newline delimited JSON.
function jsonMachine(emit, next) {
next = next || $value;
return $value;
function $value(byte) {
if (!byte) return;
if (byte === 0x09 || byte === 0x0a || byte === 0x0d || byte === 0x20) {
@morbusg
morbusg / Unicode math in plain TeX
Created March 6, 2014 12:36
Some Unicode math glyph definitions for use with plain XeTeX using a token list approach instead of family changes.
\Umathcharnumdef\aleph="2135 \Umathcharnumdef\hbar="210F
\Umathcharnumdef\imath="1D6A4 \Umathcharnumdef\jmath="1D6A5
\Umathcharnumdef\ell="2113 \Umathcharnumdef\wp="2118 \Umathcharnumdef\Re="211C
\Umathcharnumdef\Im="2111 \Umathcharnumdef\infty="221E
\Umathcharnumdef\prime="2032 \Umathcharnumdef\emptyset="2205
\Umathcharnumdef\surd="221A \Umathcharnumdef\top="22A4
\Umathcharnumdef\bot="22A5 \Umathcharnumdef\|="2016
\Umathcharnumdef\angle="2220 \Umathcharnumdef\triangle="2206
\Umathcharnumdef\backslash="005C \Umathcharnumdef\forall="2200
\Umathcharnumdef\exists="2203 \Umathcharnumdef\neg="00AC
import System.Directory
import System.Environment
import System.FilePath
import Control.Applicative ((<$>))
import Control.Arrow (first, second)
import Control.Monad (void)
import Data.Either (rights)
import Data.List (isSuffixOf)
import Data.Set (Set, (\\), empty, fromList, insert, singleton, toList, union)
import Text.Parsec
@danidiaz
danidiaz / _FP reading lists.md
Last active May 23, 2024 04:02
assorted reading lists

A series of reading lists mostly related to functional programming.

@bburky
bburky / coursera.sh
Last active June 30, 2016 17:30
Automatically configure a VM download Coursera courses
#!/bin/bash
# Automatically configure a VM download Coursera courses.
# This script works as a user data file for use with a cloud VM.
# This script will resume downloading if the VM is restarted.
# This script works with Debian jessie (or possibly Ubuntu with systemd).
# You must enroll in each course and accept the Honor of Code of each course
# before you can download them.