Skip to content

Instantly share code, notes, and snippets.

// Main.scala
class C {
var x = 0
}
object Main extends App {
val c = new C()
println("c = " + c.x)
}
@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>
@stantonk
stantonk / TestPropertiesInjection.java
Last active August 9, 2018 17:55
Example of loading a Java properties file and binding to @nAmed attributes in Guice. Handles default property settings as well. Adapted from code written by https://github.com/kylemcc
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
@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 / 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 / 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 / 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 / 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 / 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 / your-service.conf
Last active January 2, 2016 18:09
Upstart conf example
#
# Put your-service.conf in /etc/init/your-service.conf
#
# Then tell upstart about your new service:
# $ sudo initctl reload-configuration
#
# Then these commands all work as expected:
# $ sudo start your-service
# $ sudo stop your-service
# $ sudo status your-service