Skip to content

Instantly share code, notes, and snippets.

@hierynomus
hierynomus / BaseN.scala
Created October 30, 2012 20:44 — forked from marklister/BaseN.scala
Scala Hex / Decimal / Binary calculator / DSL
/**
* Scala hex / decimal binary calculator
* (c) Mark Lister 2012
* Licence Apache 2.
*/
class BaseN(b: BigInt, val baseN: Int) extends BigInt(b.underlying) {
def n(x: Int) = new BaseN(b, x)
/**
@hierynomus
hierynomus / gist:3169745
Created July 24, 2012 12:44
Deployit release alpha versions
#!/bin/sh
currentAlphaLine=`grep "version.*alpha" build.gradle`
currentAlphaVersion=`echo $currentAlphaLine | cut -d \' -f 2`
newAlphaVersion=${currentAlphaVersion%-*}-$((${currentAlphaVersion##*-} + 1))
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
echo "Repository is dirty, please commit first"
exit -1
fi
@hierynomus
hierynomus / gist:2828045
Created May 29, 2012 11:57
PlayFair Cipher in Scala
object PlayFair {
type Cipher = Map[(Int, Int), Char]
def buildCipher(p: String) : Cipher = (for (x <- 0 to 4; y <- 0 to 4) yield (x,y)).zip(chars(p)).toMap
def makeCompatible(s: String) = s toUpperCase() replace('J', 'I') filter(_.isLetter)
def chars(a: String) = {
val p = makeCompatible(a) filter { var s = Set[Char](); x => val b = s(x); s += x; !b }
p ++ ('A' to 'Z' filter (c => c != 'J' && !(p contains c)))
}