Skip to content

Instantly share code, notes, and snippets.

@tobym
tobym / github_numstat.sh
Created April 2, 2014 04:30
A script to summarize the entire activity of an organization or user on github
#!/bin/bash
#
# Usage:
# ./github_numstat.sh https://github.com/YOUR_ORG/some_repo.git
#
# Batch Usage with GitHub:
# time curl -s -H "Authorization: token YOUR_TOKEN" https://api.github.com/orgs/YOUR_ORG/repos | grep ssh_url | sed 's/.*: [^"]*"\([^"]*\).*/\1/' | xargs -I {} -P 10 ./github_numstat.sh {}
# # delete unwanted repos (like unused forks) from the 'git_numstat' by simply deleting the appropriate lines
# cat git_numstat | awk '/^[0-9]/ { inserted += $1; removed += $2 } END { print inserted - removed " total lines. " inserted " inserted, " removed " removed" }'
((fn [s] (print (list s (list (quote quote) s)))) (quote (fn [s] (print (list s (list (quote quote) s))))))
@tobym
tobym / unfiltered-all-specs.sh
Created February 5, 2014 01:50
As of aac84969e59d2f8435eff5746aa4a892ae62c67c, running `test` from the main project will result in java death.
[unfiltered] (master)$ sbt -mem 3500
Detected sbt version 0.13.0
Starting sbt: invoke with -help for other options
Using /Users/toby/.sbt/0.13.0 as sbt dir, -sbt-dir to override.
[info] Loading project definition from /Users/toby/work/scala/unfiltered/project
[warn] Multiple resolvers having different access mechanism configured with same name 'sbt-plugin-releases'. To avoid conflict, Remove duplicate project resolvers (`resolvers`) or rename publishing resolver (`publishTo`).
[info] Set current project to Unfiltered (in build file:/Users/toby/work/scala/unfiltered/)
[info] Defining */*:logLevel
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...
#!/usr/bin/env python
# encoding: utf-8
"""
cmsketch.py
An implementation of count-min sketching from the paper due to Cormode and
Muthukrishnan 2005
"""
@tobym
tobym / depend-on-git-repo.scala
Created January 14, 2014 14:17
Demonstration of how an SBT (http://www.scala-sbt.org/) project can have a dependency on a git repo instead of an artifact.
object Plugins extends Build {
lazy val plugins = Project("root", file("."))
.dependsOn(uri("git://github.com/your-org/your-project.git#0.8"))
}
@tobym
tobym / unexpected-companion-object-loaded.scala
Created October 28, 2013 22:53
Unexpected load of a companion object
class Foo(value: String = "default")
object Foo extends Foo("object here") {
println("companion object loaded!!!")
}
class Bar extends Foo
class Baz extends Foo("this works")
class MySpec extends org.specs2.mutable.Specification {
def serviceSpec[T](spec: JobTrackingService => T): T = MyDatabase.withTransaction { db =>
val svc = new MyService
spec(svc)
}
"service" should {
"test using transactions" in serviceSpec { svc =>
svc.foo must_== "foo"
}
@tobym
tobym / commaFormatNumber.vim
Last active December 21, 2015 21:18
This script adds a "comma format" function to vim. In normal node, put your cursor on a number like 12345 and type `cfn`. The number will transform to 12,345.
function! CommaFormatNumber()
" 0. start position is in current word. We assume we are in normal mode.
" Use 'viw' to visually select the word as a hack to move the cursor to the
" end of the current word (prevents accidentally moving off the number).
" 1. go mark the beginning of the number
" 2. go mark the end of the number
" 3. apply the search/replace-with-commas the correct number of times.
exe "normal viw\<Esc>bmaemb"
let startpos = getpos("'a")[2]
let endpos = getpos("'b")[2]
@tobym
tobym / scala.vim
Created August 9, 2013 20:53
Vim snippet: Find usages of current word (under the cursor) in main Scala sources
" Find current word scala main sources.
" Requires Ack plugin.
function! FindUsagesScala()
:Ack --scala -G main -w <cword>
endfunction
nmap <F7> :call FindUsagesScala()<CR>
@tobym
tobym / pwdx
Created February 11, 2013 21:53
pwdx for mac, updated
#!/bin/bash
lsof -a -p $1 -d cwd -Fn | tail -1 | sed 's/.//'