Skip to content

Instantly share code, notes, and snippets.

@smoofra
smoofra / git_patch_download.rb
Created July 23, 2015 01:11
Homebrew snippet to use a git branch as a patch
class GitPatchDownloadStrategy < GitDownloadStrategy
def initialize name, resource
super
@baseref = meta[:base]
end
def stage
Homebrew.system("git", "-C", cached_location, "diff", @baseref, @ref) do
$stdout.reopen('patch')
end
end
@smoofra
smoofra / git-testmerge.sh
Created July 25, 2015 01:53
performs a git-merge and prints a tree-ish without modifying any of your state
#!/bin/sh
set -e
. "$(git --exec-path)"/git-sh-setup
cleanup() {
if [ ! -z "$tmp" ]; then
rm -rf "$tmp"
fi
}
tmp=""
trap cleanup EXIT
@smoofra
smoofra / local-directory-download.rb
Last active August 29, 2015 14:25
Homebrew formula snippet to grab source from a local directory
class LocalDirectoryDownloadStrategy < AbstractDownloadStrategy
def initialize(name, resource)
super
@url = @url.sub(%r[^file://], "")
end
def stage
ohai "cp -r #{@url}/* ."
cp_r(Dir[@url + "/*"], ".")
@smoofra
smoofra / delegate.cpp
Created April 15, 2017 20:07
delegates: c++ function pointer + context object
#include <utility>
#include <functional>
#include <stdio.h>
template<class S> class delegate;
template<class Ret, class ... Args>
@smoofra
smoofra / quicklook.ipynb
Last active August 15, 2018 19:58
viewing QuickLook thumbnail
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@smoofra
smoofra / export-scuttle-to-owncloud
Created August 11, 2017 17:15
export scuttle bookmarks into a form OwnCloud can import
#!/usr/bin/python
import mysql.connector
import getpass
import cgi
import sys
mysqlpass = getpass.getpass("password for mysql: ", sys.stderr)
cnx = mysql.connector.connect(user='root',
@smoofra
smoofra / atlantic.ipynb
Created July 13, 2018 21:12
battle of the atlantic
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@smoofra
smoofra / chunks.py
Last active September 18, 2018 18:47
chunks
def chunks(iterable, n):
"""group elements of iterable into chunks of size n and yield an iterator for
each chunk"""
i = iter(iterable)
def groupiter(first):
yield first
for x in range(n-1):
try:
yield next(i)
@smoofra
smoofra / csv_parser.py
Created September 22, 2018 19:34
csv parser example
#!/usr/bin/python
import csv
from StringIO import StringIO
with open('test.csv', 'rb') as f:
data = f.read().decode('utf8')
# remove unicode byte-order marker if it exists
if data.startswith(u'\uFEFF'):
data = data[1:]