Skip to content

Instantly share code, notes, and snippets.

View cb372's full-sized avatar

Chris Birchall cb372

View GitHub Profile
@cb372
cb372 / init-gradle.sh
Last active December 15, 2015 20:00
Gradle boilerplate generator
#!/bin/sh
content=$(cat <<EOF
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'eu.appsatori:gradle-fatjar-plugin:0.2-rc1'
@cb372
cb372 / x-in-xs.txt
Last active December 18, 2015 16:39
Python-style "x in xs" testing in Scala using implicit conversion and duck typing. Sinful but convenient.
scala> implicit class WithInMethod(obj: Any) {
| def in(a: {def contains(e: Any): Boolean}): Boolean = a.contains(obj)
| }
warning: there were 1 feature warnings; re-run with -feature for details
defined class WithInMethod
scala> "foo" in List("1", "2")
res3: Boolean = false
scala> "foo" in List("foo", "bar")
@cb372
cb372 / scala-repl.vim
Created July 12, 2013 03:05
Write the current vim buffer to a temp file and load it in the Scala REPL
" Write the current buffer to a temp file and load it in the Scala REPL
function RunInScalaREPL()
let l:tmpfile = tempname() . '.scala'
execute 'write ' . l:tmpfile
execute '!scala -i ' . l:tmpfile
endfunction
command Scala call RunInScalaREPL()
command REPL call RunInScalaREPL()
@cb372
cb372 / gist:6484517
Created September 8, 2013 12:54
Mapping a Set
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_09).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Foo(a: Int, b: Int)
defined class Foo
scala> Set(Foo(1, 10), Foo(2, 10), Foo(3, 20))
res0: scala.collection.immutable.Set[Foo] = Set(Foo(1,10), Foo(2,10), Foo(3,20))
@cb372
cb372 / gist:6548989
Last active December 22, 2015 23:49
Installing ruby 2.0.0-p247 on OS X with un-broken readline
  1. Install OpenSSL via homebrew, if you haven't already. Without this, ruby install will fail trying to compile openssl.

    brew install openssl
    
  2. Install readline via homebrew, if you haven't already. This allows irb to support multi-line characters correctly in.

brew install readline

@cb372
cb372 / pom-vbump.py
Last active November 1, 2019 10:07
Version-bump script for Maven projects. Reads pom.xml, parses the version, increments it and either updates pom.xml or writes an updated pom to stdout.
#! /usr/bin/env python
#
# coding: utf-8
"""
Version-bump script for Maven projects.
Reads pom.xml, parses the version, increments it and writes an updated pom to stdout.
Usage:
pom-vbump.py [-i] [-v <new version number>] [path to pom.xml]
@cb372
cb372 / git_checkout.sh
Last active December 26, 2015 00:39
Utility method to checkout a given git branch or tag. Useful in deployment scripts. Requires git 1.8.x.
#!/bin/bash
# Checkout the given branch or tag to the given directory.
# Clones the repo if a clone does not already exist.
#
# Arguments:
# $1 = Git repo URL e.g. #git@github.com:foo/bar.git" (Mandatory)
# $2 = Local directory e.g. /tmp/checkout" (Mandatory, must be absolute path)
# $3 = Branch or tag name e.g. "develop" or "0.1" (Mandatory)
function git_checkout {
var casper = require('casper').create();
casper.cli.drop("cli");
casper.cli.drop("casper-path");
if (casper.cli.args.length === 0 && Object.keys(casper.cli.options).length === 0) {
casper.echo('Usage: phantomjs download-java.js <name of file to download>');
casper.echo('Example: phantomjs download-java.js jdk-7u45-linux-x64.rpm');
casper.exit(1);
}
@cb372
cb372 / foo.js
Created November 3, 2013 16:59
Trying to reproduce problem with file downloads using CasperJS. Failed to reproduce problem - User Agent and cookies are sent as expected.
// Note: Add a line to /etc/hosts before running.
// 127.0.0.1 www.oracle.com download.oracle.com
var casper = require('casper').create();
casper.userAgent('Custom user agent');
casper.start('http://www.oracle.com:4567/', function() {
this.echo('Opened page at /');
});
@cb372
cb372 / gist:7576659
Last active December 28, 2015 23:09
Generating a B-encoded mail subject
val encoding = "iso-2022-jp"
val subject = "こんにちは、世界"
val base64 = javax.xml.bind.DatatypeConverter.printBase64Binary(subject.getBytes(encoding))
val bEncoded = s"=?$encoding?B?$base64?="