Skip to content

Instantly share code, notes, and snippets.

View coffeemancy's full-sized avatar

C coffeemancy

  • New Hampshire, USA
View GitHub Profile
from itertools import chain
def lcs(s, t):
"""Find longest common substring in strings.
>>> lcs('abcdxyz', 'xyzabcd')
(4, 'abcd')
>>> lcs('abcdxyzabcyzabcdzabcdefghijkllm', 'xyzabcdefghijklm')
@coffeemancy
coffeemancy / completion.py
Created April 3, 2017 15:37
bash/zsh-completion for python click tools
# -*- coding: utf-8 -*-
"""
Bash completion for click command line interfaces.
Provides bash completion helpers for command-line interfaces.
"""
# batteries included
from __future__ import absolute_import
# third party
@coffeemancy
coffeemancy / build.sh
Created April 3, 2017 15:31
python package boilerplate
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
function _error() {
>&2 printf "\e[31mERROR: $@\e[00m\n"
exit 1
}
@coffeemancy
coffeemancy / zsh-up.sh
Last active December 22, 2016 16:09
Setup oh-my-zsh on remote server when supplied SSHFN
#!/usr/bin/env bash
set -euo pipefail
export IFS=$'\n\t'
SSHFN=$@
ohmyzsh="curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -o \~/install.sh"
#!/usr/bin/env python3
edges = {(1, 'a'): [2, 3],
(2, 'a'): [2],
(3, 'b'): [4, 2],
(4, 'c'): [5]}
edges2 = {(1, 'a'): [1],
(2, 'a'): [2]}
@coffeemancy
coffeemancy / plugins.sbt
Created November 14, 2016 15:40
test scala with ruby
/* put this file in ~/.sbt/0.13/plugins/plugins.sbt */
/* style */
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
/* coursier -- faster dependencies */
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M14")
@coffeemancy
coffeemancy / watch.rb
Created November 1, 2016 17:00
Using ruby to test python on file changes
#!/usr/bin/env ruby
# REQUIREMENTS
#
# Needs ruby and the watchr gem, which can be installed
# globally via:
#
# sudo gem install watchr
# USAGE
@coffeemancy
coffeemancy / wait_for_dns.py
Last active January 22, 2016 18:44
wait for DNS
#!/usr/bin/env python
try:
import dns.exception
import dns.resolver
except ImportError as ex:
raise SystemExit('You need to pip install dnspython')
import signal
import sys
@coffeemancy
coffeemancy / idonethis.sh
Created December 9, 2015 18:43
idonethis bash functions
## IDoneThis
function _set_idonethis_token {
local token=$(pass datarobot/idonethis | grep Token | cut -d ' ' -f 2)
export IDONETHIS_TOKEN=${token}
}
function idid {
_set_idonethis_token
local team='datarobot-work-notes'
@coffeemancy
coffeemancy / gist:74ac4bbb3ea8ddbe73c0
Created September 25, 2014 03:23
2048 collapse row clojure
(defn collapse-row [row]
(filterv (complement nil?)
(reduce (fn [acc elm]
(let [n (peek acc)]
(if (= n elm)
(conj (pop acc) (* n 2) nil)
(conj acc elm))))
[nil]
row)))