Skip to content

Instantly share code, notes, and snippets.

View gbougeard's full-sized avatar

Greg BOUGEARD gbougeard

View GitHub Profile
@ohac
ohac / hmacsha1.scala
Created February 22, 2010 09:00
HMAC-SHA1 for Scala
import javax.crypto.spec.SecretKeySpec
import javax.crypto.Mac
object A {
def main(args: Array[String]): Unit = {
val secret = new SecretKeySpec("the_secret".getBytes, "HmacSHA1")
val mac = Mac.getInstance("HmacSHA1")
mac.init(secret)
val result: Array[Byte] = mac.doFinal("foo".getBytes)
println(result.map(_.toString).mkString(","))
@jorgeortiz85
jorgeortiz85 / PrivateMethodCaller.scala
Created April 7, 2011 15:41
Calling private methods in Scala
// Usage:
// p(instance)('privateMethod)(arg1, arg2, arg3)
class PrivateMethodCaller(x: AnyRef, methodName: String) {
def apply(_args: Any*): Any = {
val args = _args.map(_.asInstanceOf[AnyRef])
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass)
val parents = _parents.takeWhile(_ != null).toList
val methods = parents.flatMap(_.getDeclaredMethods)
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found"))
@textarcana
textarcana / git-log2json.sh
Last active March 1, 2024 05:26
Convert Git logs to JSON. The first script (git-log2json.sh) is all you need, the other two files contain only optional bonus features 😀THIS GIST NOW HAS A FULL GIT REPO: https://github.com/context-driven-testing-toolkit/git-log2json
#!/usr/bin/env bash
# Use this one-liner to produce a JSON literal from the Git log:
git log \
--pretty=format:'{%n "commit": "%H",%n "author": "%aN <%aE>",%n "date": "%ad",%n "message": "%f"%n},' \
$@ | \
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
perl -pe 's/},]/}]/'
@julienrf
julienrf / Application.scala
Created April 26, 2012 20:47
Write a Mapping[A] and get a QueryStringBindable[A] for free
// --- Definition of a query string binder for type A using a Mapping[A]
object Binders {
implicit def mappingBinder[A](implicit mapping: Mapping[A]) = new QueryStringBindable[A] {
override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]] = {
val data = for {
(k, ps) <- params
if k startsWith key
p <- ps.headOption
} yield (k.drop(key.length + 1), p)
@jboner
jboner / latency.txt
Last active May 5, 2024 03:12
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@gclaramunt
gclaramunt / planes.scala
Created June 6, 2012 18:08
Very simple phantom types example
trait FlightStatus
trait Flying extends FlightStatus
trait Landed extends FlightStatus
case class Plane[Status <: FlightStatus]()
def land(p:Plane[Flying])=Plane[Landed]()
def takeOff(p:Plane[Landed])= Plane[Flying]()
val plane = new Plane[Landed]()
@brandonb927
brandonb927 / osx-for-hackers.sh
Last active May 5, 2024 13:30
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.
#!/bin/sh
###
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/5b3c8418ed42d93af2e647dc9d122f25cc034871/.osx
@egaumer
egaumer / DSL Examples
Last active June 26, 2019 20:21
Some example queries using elastic.js
# simple match all query with term facet
ejs.Request()
.indices("myindex")
.types("mytype")
.query(ejs.MatchAllQuery())
.facet(
ejs.TermsFacet('url')
.field('url')
.size(20))
@revolunet
revolunet / angularjs.md
Last active October 22, 2021 00:36
BeerJS + AngularJS Paris le 25/2

AngularJS best ressources

Following the AngularJS PARIS meetup (25/2 à 19h à Paris with @sampaccoud @dzen @_kemar @tchack13 @vinz et @revolunet)

Here's our best AngularJS ressources : twitter, github, articles & blogs. Please comment and add your good stuff !