Skip to content

Instantly share code, notes, and snippets.

@stantonk
stantonk / jira-table.sh
Created February 17, 2014 22:12
Easily copy results of a SQL query in SequelPro (or any program that uses tab-delimited data when copying from a database or spreadsheet program) and turn it into JIRA flavored Markdown to produce a nice table in the comments.
#!/usr/bin/env bash
# Will create a table in JIRA markup from a tab-delimited copy-paste buffer from
# SequelPro so you can embed a SQL query results easily in a JIRA ticket in table
# form.
pbpaste | tr '\t' '|' | sed 's/^/|/' | sed 's/$/|/' | pbcopy
@stantonk
stantonk / fab_utils.py
Last active August 29, 2015 13:56
Reliable way to determine if a process on a remote host is running or not using Python and Fabric. Tested on CentOs 5.10 and Ubuntu 12.04
# NOTE: the hide('warnings', 'running', 'stdout', 'stderr') quiets the
# dumping of the commands fabric runs and its responses, which I find
# rather annoying.
def is_running(pidfile, pidpath):
with cd(pidpath):
if exists(pidfile):
with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True):
return run('ps -p $(cat %s) --no-header' % pidfile).succeeded
else:
@stantonk
stantonk / channels.go
Created March 12, 2014 04:23
Messing with channels and goroutines
package main
import "fmt"
import "time"
func consume(c chan int) {
for {
fmt.Println("sleeping for a second...")
time.Sleep(1000 * time.Millisecond)
fmt.Println("consumed:", <-c)
@stantonk
stantonk / httpJson.go
Last active August 29, 2015 13:57
messing http & json in go
package main
import "fmt"
import "net/http"
import "io/ioutil"
import "encoding/json"
func main() {
resp, err := http.Get("https://graph.facebook.com/sproutsocialinc")
@stantonk
stantonk / blah.scala
Created June 12, 2014 04:18
Black magic to tell sbt to choose the first duplicate class when resolving dependency collisions instead of just failing out.
/**
* Black magic to tell sbt to choose the first duplicate class when resolving dependency collisions instead of just
* failing out.
*/
mergeStrategy in assembly <<= (mergeStrategy in assembly) {
(old) => {
case x if Assembly.isConfigFile(x) =>
MergeStrategy.concat
case PathList(ps@_*) if Assembly.isReadme(ps.last) || Assembly.isLicenseFile(ps.last) =>
MergeStrategy.rename
@stantonk
stantonk / sample.py
Created June 13, 2014 21:52
Randomly sample a large ass file
import argparse
import mmap
import random
def get_line_count(filename):
linecount = 0
with open(args.filename, "r+b") as f:
mm = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
@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)
}
@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 :)