Skip to content

Instantly share code, notes, and snippets.

View pjan's full-sized avatar

pjan vandaele pjan

View GitHub Profile
@pjan
pjan / safe_equals.scala
Created May 9, 2015 13:49
Comparison of strings in a time attack safe way
def safeEquals(a: String, b: String) = {
val a_bytes = a.getBytes
val b_bytes = b.getBytes
if (a_bytes.length != b_bytes.length) {
false
}
else {
a_bytes.zip(b_bytes).foldLeft(0){ (acc, t) => acc + (t._1 ^ t._2) } == 0
}
}
@pjan
pjan / gist:706c1a4130fbd66ad614
Created September 13, 2014 06:13
Install Docker with sudoless docker commands
# install docker (bootstrap)
curl -sSL https://get.docker.io/ubuntu/ | sudo sh
# add current user to docker group
sudo gpasswd -a ${USER} docker
# restart the docker daemon
sudo service docker restart
### Keybase proof
I hereby claim:
* I am pjan on github.
* I am pjan (https://keybase.io/pjan) on keybase.
* I have a public key whose fingerprint is ACFB 2F34 1D70 9617 496F C3E0 8A96 A1C9 3CA1 3DF6
To claim this, I am signing this object:
import play.api.libs.json._
import play.api.libs.functional.syntax._
case class User(id: Int, name: String, partner: Option[String])
// Json format without null
val userReads: Reads[User] = (
(JsPath \ "id").read[Int] and
(JsPath \ "name").read[String] and
(JsPath \ "partner").readNullable[String]
@pjan
pjan / scala-init.sh
Last active December 24, 2015 11:59
Scala sbt project bootstrap script: > wget https://gist.github.com/pjan/6795076/raw -O scala-init.sh && source scala-init.sh
#!/bin/bash
SBT_VERSION="0.12.4"
BUILD_VERSION="0.1.0-SNAPSHOT"
BUILD_SCALA_VERSION="2.10.2"
BUILD_JVM_VERSION="1.7"
function doIt() {
NAME=$1
ORGANIZATION=$2
@pjan
pjan / iOS.ovpn
Created August 26, 2013 02:41
Openvpn .ovpn template for iOS devices.
client
dev tun
proto udp
remote [server name/address] 1194
resolv-retry infinite
nobind
reneg-sec 3600
@pjan
pjan / OSX_Port_Redirection
Created August 6, 2013 06:03
Port redirection in OSX
# you have to run this after every reboot (route is not persistent)
# 2 lines added below; deduct if more needed...
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to me 80
sudo ipfw add 101 fwd 127.0.0.1,8443 tcp from any to me 443
@pjan
pjan / new_postgres_user_db
Created August 6, 2013 05:14
Add a new user and accompanying database to postgres
sudo -u postgres createuser -D -A -P my_db_user
sudo -u postgres createdb -O my_db_user my_db
@pjan
pjan / postgres_user_pw
Last active December 20, 2015 16:29
Add postgres user password
sudo -u postgres psql postgres
postgres=# \password postgres
Enter new password: (enter your password)
Enter it again: (re-enter your password)
postgres=# (press control+d to exit postgres)