Skip to content

Instantly share code, notes, and snippets.

@stantonk
stantonk / vimrc.vim
Created August 5, 2014 02:59
View git blame, hg blame, svn blame in vim or MacVim. Note, you must first select the source lines with visual mode, then hit the appropriate leader key sequence. Enjoy!
" version control blame of selected lines
"vmap <Leader>b :<C-U>!svn blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR>
vmap <Leader>g :<C-U>!git blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR>
vmap <Leader>h :<C-U>!hg blame -fu <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR>
// Main.scala
class C {
var x = 0
}
object Main extends App {
val c = new C()
println("c = " + c.x)
}
import sys
class TestTriedToAccessNetwork(BaseException):
pass
if 'test' in sys.argv:
import socket
class PatchedSocket(socket.socket):
@stantonk
stantonk / quick-collapse.sh
Last active August 29, 2015 14:11
Mercurial hg: Quickly squash a recent, unpushed commit with some un-committed changes. This is really handy when you forgot to do something, or a linter or CI suite catches errors before you push / merge.
#!/usr/bin/env bash
# N.B. requires patch queues (mq) enabled in your .hgrc. to finish this up
# and turn into a real commit, do `hg qfinish -a`
now=`date +"%s"`
patch_name='$now-temporary'
hg qnew $patch_name
hg qpop
@stantonk
stantonk / pom.sh
Last active August 29, 2015 14:11
open Java Maven project in IntelliJ from the OS X terminal
#!/usr/bin/env bash
open -a /Applications/IntelliJ\ IDEA\ 13\ CE.app/ pom.xml
# best as a bash alias :)
@stantonk
stantonk / KeyValueStore.java
Last active August 14, 2016 17:29
Simple threadsafe LevelDB-backed key-value store for Java
/**
<dependency>
<groupId>org.fusesource.leveldbjni</groupId>
<artifactId>leveldbjni-all</artifactId>
<version>1.7</version>
</dependency>
*/
import com.google.common.base.Optional;
import org.iq80.leveldb.DB;
@stantonk
stantonk / eplot.rb
Created April 30, 2015 21:37
featureful command line plotting of data in a Linux shell, made easy with eplot, a gnuplot wrapper. This version is modified slightly, per the instructions found here: http://stackoverflow.com/questions/123378/command-line-unix-ascii-based-charting-plotting-tool#answer-12868778. eplot in its original form can be found here: http://liris.cnrs.fr/…
#!/usr/bin/ruby
# **************************************************************************
# ### modified based on:
# http://stackoverflow.com/questions/123378/command-line-unix-ascii-based-charting-plotting-tool
# ###
# eplot
# Written by Christian Wolf
#
# eplot ("easy gnuplot") is a shell script which allows to pipe data easily
# through gnuplot and create plots quickly, which can be saved in postscript,
@stantonk
stantonk / get_valid_tlds.py
Last active July 11, 2022 22:36
Updated list of valid TLDs (Top Level Domains). Python script grabs the IANA database and formats it into a set datatype.
# requirements.txt
# pip install requests
# pip install BeautifulSoup4
import codecs
import requests
from bs4 import BeautifulSoup
PER_LINE = 12
@stantonk
stantonk / run-tests-hook.sh
Last active August 29, 2015 14:23
In a mercurial or git pre-commit or pre-push hook: detect the type of project and invoke the appropriate test runner for various projects. So far Maven and Django projects are supported. Trivial to add others. No-ops on unknown project types.
#!/usr/bin/env bash
################################################################################
# Use as a global mercurial/git pre commit or pre push hook to detect the type
# of project and run unittests before allowing a commit or push to a remote
# repository.
#
# Handy so that you don't have to remember to add test running hooks to every
# repo clone/fork you have.
#
# ********** MERCURIAL SETUP *************
@stantonk
stantonk / loop.py
Last active August 29, 2015 14:24
Indefinitely cycle through some sequence in Python, e.g. for object pools.
# loop foreva-eva
def loop(sequence):
while True:
for elem in sequence:
yield elem
# example usage, imagine you have a set of things you want
# to cycle through, removing bad ones as they appear
class ObjectPoolEmptyError(Exception):