Skip to content

Instantly share code, notes, and snippets.

@noel-yap
noel-yap / CompiledRegexMatcher.scala
Created September 24, 2012 21:54
Regex matchers in Scala
package org.siliconvalleypatterns
/**
* @author [email protected]
*/
class CompiledRegexMatcher(val regex: String) {
def compile(): List[Token] = {
def compile(regex: String): List[Token] = {
if (regex.isEmpty) {
Nil
@noel-yap
noel-yap / GuiceExploratoryTest.java
Created September 25, 2012 22:07
Guice AssistedInject with Generics
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import org.junit.Test;
@noel-yap
noel-yap / GuiceExploratoryTest.java
Created September 28, 2012 22:00
Guice AssistedInject
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import org.junit.Test;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@noel-yap
noel-yap / gist:5061220
Created February 28, 2013 23:57
Automates submission of homework for "Functional Programming Principles in Scala" Coursera course.
#!/bin/bash
email_addr="$1"
course_password="$2"
echo "${email_addr}" "${course_password}" | sbt
@noel-yap
noel-yap / gist:5917421
Created July 3, 2013 12:15
Gradle task that outputs all tasks and their outputs.
task outputs() << {
tasks.each { task ->
println "${task.name}.outputs: ${task.outputs.getFiles().asType(Collection)}"
}
}
@noel-yap
noel-yap / TaskUtil.groovy
Created September 16, 2013 18:27
Recursively set Gradle task dependency.
class TaskUtil {
static def recursivelyApplyToTaskDependencies(Task parent, Closure closure) {
closure(parent)
parent.dependsOn.findAll { dependency ->
dependency instanceof Task
}.each { task ->
recursivelyApplyToTaskDependencies(task, closure)
}
}
@noel-yap
noel-yap / iteratively-convert-perforce-repository-to-git.sh
Last active August 29, 2015 13:57
Iteratively convert Perforce repository to git -- preserves existing git commit hashes.
#!/bin/bash -evx
PERFORCE_DEPOT_PATH=$1
GIT_REPOSITORY_URL=$2
git_project_name=$(echo ${GIT_REPOSITORY_URL} | sed -e 's|^.*/||' -e 's|\.git||')
rm -rf ${git_project_name}
git clone ${GIT_REPOSITORY_URL}
#!/bin/bash -evx
PERFORCE_DEPOT_PATH=$1@all
GIT_REPOSITORY_URL=$2
git_project_name=$(echo ${GIT_REPOSITORY_URL} | sed -e 's|^.*/||' -e 's|\.git||')
rm -rf ${git_project_name}
git clone ${GIT_REPOSITORY_URL}
# Allows one to have a multi-line shebang just like in Scala. Just as in Scala, be sure to end the multi-line shebang with a !#.
# example usage: trampoline "${GRADLE_HOME}/bin/gradle" "$@"
function trampoline() {
local command=("$@")
umask 077
tmpdir="$(mktemp -d -t $$.XXXXXXXXXXXXXXXX)"
trap 'rm -rf -- "${tmpdir}"' INT TERM HUP EXIT
def doHttpPost(final String path, final String query) {
final authority = 'example.com'
final url = new URL("http://${authority}/${path}")
final connection = url.openConnection()
connection.with {
setRequestMethod('POST')
doOutput = true
final writer = new OutputStreamWriter(outputStream)
writer.with {