Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
exec /opt/scala-2.10/bin/scala -feature "$0" "$@"
!#
object Primes {
private lazy val notDivisibleBy2: Stream[Long] = 3L #:: notDivisibleBy2.map(_ + 2)
private lazy val notDivisibleBy2Or3: Stream[Long] = notDivisibleBy2
.grouped(3)
.map(_.slice(1, 3))
.flatten
@noel-yap
noel-yap / sum-of-power.scala
Last active November 29, 2016 19:51
Generates formulae for sum of powers.
#!/bin/bash
exec /opt/scala-2.10/bin/scala -feature "$0" "$@"
!#
import scala.language.postfixOps
/**
* From https://stackoverflow.com/questions/25129721/scala-memoization-how-does-this-scala-memo-work.
*
* Generic way to create memoized functions (even recursive and multiple-arg ones)
# moved to noel-yap/.bash
@noel-yap
noel-yap / github-upstream-set.sh
Last active July 15, 2016 23:07
Adds `upstream` to clone of Github repo.
#!/bin/bash
proj_repo=$(git config --get remote.origin.url | sed -E -e 's|(ssh://)?git@github.com[/:]||' -e 's|\.git$||')
upstream=$(curl "https://api.github.com/repos/${proj_repo}" | jq '.parent.git_url' | sed -e 's|"||g')
git remote add upstream ${upstream}
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 {
# 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
#!/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}
@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}
@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 / 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)}"
}
}