Skip to content

Instantly share code, notes, and snippets.

from itertools import permutations
WORD_FILE = '.../words'
words = set(x.strip() for x in open(WORD_FILE).readlines())
LETTERS = 'abcdefg'
perms = set((''.join(x).split())[0] for x in permutations(LETTERS+' '))
Mirroring a Git repostory
The firm I recently stated working at just moved to Git and I am the only resource then knows Git. I get asked so many times a day on how to mirror a git repostory.
From the birds eyes very its very easy:
git clone --mirror git@git.com:project project
cd project
git remote add github git@github.com:username/project.git
@mcenirm
mcenirm / xx2a
Created June 4, 2014 18:48
Wrapper script for jp2a that will attempt to convert other image formats to JPEG. Requires ImageMagick's convert (or compatible).
#!/bin/bash
JP2A=$(dirname "$0")/jp2a
declare -a jp2aopts
while [[ $# -gt 0 ]] ; do
case "$1" in
-) break ;;
--) shift ; break ;;
-*) jp2aopts+=( "$1" ) ; shift ;;
@mcenirm
mcenirm / show_recent_files.bash
Created June 5, 2014 20:39
For a set of directories, show the most recent files found.
#!/bin/bash
for d in "$@" ; do
echo
echo "${d}"
find "${d}" -type f -printf '%T+ %P\n' | sort | cat -n | tail -3
done
@mcenirm
mcenirm / .bash_profile
Last active August 29, 2015 14:15
.bash_profile on Mac OS X for homebrew, python
# Github API token, so that homebrew doesn't hit such a low rate limit
if [ -r ${HOME}/.github/api_token ] ; then
export HOMEBREW_GITHUB_API_TOKEN=$(< ${HOME}/.github/api_token)
fi
# Per-user python modules-installed executables
export PATH=${HOME}/Library/Python/$(python -c 'from sys import version_info as v; print(".".join(map(str,v[0:2])))')/bin${PATH+:${PATH}}
# Need a readlink that works like on linux
@mcenirm
mcenirm / gist:122c6dd18c91ccba4c5c
Created April 19, 2015 20:10
Extract data urls from gltf (or any json?) into separate files
name=box
cat "$name.gltf" \
| jq -r 'leaf_paths | if .[length-1] == "uri" then join(".") else empty end' \
| while read p ; do
cat "$name.gltf" \
| jq -r ".$p" \
| sed -e 's/^[^,]*,//' \
| base64 -d \
> "$name.$p.out"
done
@mcenirm
mcenirm / gist:1211576
Created September 12, 2011 15:37
Disable "powered by geomajas" watermark on a Geomajas MapWidget
public class Application implements EntryPoint {
...
public void onModuleLoad() {
...
final MapWidget map = new MapWidget("mapMain", "app") {
@Override
protected void initializationCallback(GetMapConfigurationResponse r) {
super.initializationCallback(r);
Map<String, MapAddon> mapAddons = getMapAddons();
for (MapAddon addon : mapAddons.values()) {
@mcenirm
mcenirm / merge.js
Created May 3, 2012 14:57
merge JS object properties
// http://stackoverflow.com/a/4320620
// merge object properties
// earlier objects override later objects
function merge () {
var o = {}
for (var i = arguments.length - 1; i >= 0; i --) {
var s = arguments[i]
for (var k in s) o[k] = s[k]
}
return o
@mcenirm
mcenirm / gist:2771175
Created May 22, 2012 19:43
Download a resource from a URL and save as a file in the current directory
/**
* Download a resource from a URL and save as a file in the current directory.
* (no overwrite, no timestamp checking, assumes URL has a sensible filename-like path)
*/
File grabRemoteUrlAsLocalFile(String remote) throws MalformedURLException, IOException {
URL remoteUrl = new URL(remote);
String localName = url2filename(remoteUrl);
File localFile = new File(localName);
Path localPath = localFile.toPath();
if (!localFile.exists()) {
@mcenirm
mcenirm / gist:2771534
Created May 22, 2012 20:47
Convert HTML to XML using TagSoup
XMLReader tagSoupReader = new org.ccil.cowan.tagsoup.Parser();
Transformer identityTransformer = TransformerFactory.newInstance().newTransformer();
Reader sourceReader = new FileReader(sourceFile);
InputSource sourceInputSource = new InputSource(sourceReader);
Source xmlSource = new SAXSource(tagSoupReader, sourceInputSource);
Result outputTarget = new StreamResult(outputFile);
identityTransformer.transform(xmlSource, outputTarget);