Skip to content

Instantly share code, notes, and snippets.

@stantonk
stantonk / initproj
Created December 8, 2013 05:35
bootstrap scala projects with sbt..learning some other bash crap, etc.
#!/usr/bin/env bash
# build.sbt template
SBT_TMPL="/tmp/build.sbt.template"
cat << 'EOF' > $SBT_TMPL
name := "%name%"
version := "%version%"
scalaVersion := "%scalaversion%"
@stantonk
stantonk / simple_http_get.scala
Last active December 30, 2015 16:19
making a simple http GET with scala to facebook's api
import scala.io._
val response = Source.fromURL("http://graph.facebook.com/SproutSocialInc")
val jsonString = response.mkString
println(jsonString)
@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
@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 / 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;