Skip to content

Instantly share code, notes, and snippets.

@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
(*
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@jasonmc
jasonmc / Program.fs
Last active November 16, 2017 21:51
(*
Copyright 2017 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@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)
curl -s "http://httpbin.org/get?a=echo%20'you%20moron'" | jq '.args.a' | tr -d '"' | bash
@jasonmc
jasonmc / gist:3344878
Created August 13, 2012 23:42
Test sanitizing names for Mercurial to Git conversion.
import subprocess
from mercurial import commands
from mercurial import ui
from mercurial import localrepo
def sha_string(hash):
import base64
return base64.b16encode(hash).lower()
@jasonmc
jasonmc / gist:3344867
Created August 13, 2012 23:39
Find unnamed heads in Mercurial
from mercurial import commands, ui, localrepo
import sys
# default git branch name
cfg_master='master'
origin_name=''
def get_branch(name):
# 'HEAD' is the result of a bug in mutt's cvs->hg conversion,
@jasonmc
jasonmc / gist:2523587
Created April 29, 2012 02:17
Go directory tree builder
package main
import (
"os"
"log"
"fmt"
"path/filepath"
"strconv"
"strings"
)
@jasonmc
jasonmc / gist:2474995
Created April 24, 2012 00:39
Clojure directory tree builder
(defn buildMap [fl]
(cond
(.isDirectory fl)
(let [subfiles (filter (complement nil?) (map buildMap (.listFiles fl)))]
(list (.getAbsolutePath fl) subfiles (reduce + (map last subfiles)))
)
(.isFile fl)
(list (.getAbsolutePath fl) (.length fl))
)
)
@jasonmc
jasonmc / hack.sh
Created March 31, 2012 20:31 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#