Skip to content

Instantly share code, notes, and snippets.


Johan Dahlberg johandahlberg

View GitHub Profile
from pathlib import Path
from queue import Queue
def bf_search(search_for, root, max_depth):
class PathLevel():
def __init__(self, path, level):
self.path = path
self.level = level
View CompleteTutorial.scala
package controllers
import java.nio.charset.StandardCharsets
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import models.RegisterFacebook
import org.apache.commons.codec.binary.Hex
import play.api.Logger
import play.api.libs.concurrent.Execution.Implicits.defaultContext
View RecieveMessage.scala
def rawbuffer2JsValue(rawBuffer: RawBuffer): Option[JsValue] = {
for {
bytes <- rawBuffer.asBytes()
} yield {
def receiveFacebookMessages = withVerifiedPayload {
Action (parse.raw) {
View VerifyPayload.scala
val verificationService = new SHA1VerificationService()
def withVerifiedPayload[A](action: Action[RawBuffer])= Action.async(parse.raw) { request =>
val xHubSignatureOption = request.headers.get("X-Hub-Signature")
Logger.debug("Attempting to verify payload signature.")
val verified =
for {
signature <- xHubSignatureOption
View VerificationService.scala
class SHA1VerificationService {
private val secret = "<your key>"
private def computeSHA1Hash(payloadBytes: Array[Byte], secret: String): String = {
val secretKeySpec = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), HMAC_SHA1_ALGORITHM)
val mac = Mac.getInstance(HMAC_SHA1_ALGORITHM)
View Models.scala
case class FacebookPostingMessages(`object`: String, entry: Seq[MessagePostEntry]) {
def messages(): Seq[Message] = {
case class Correspondent(id: String)
case class MessagePostEntry(id: String, time: Long, messaging: Seq[Messaging])
case class Messaging(sender: Correspondent, recipient: Correspondent, timestamp: Long, message: Message)
case class Message(mid: String, seq: Long, text: String)
johandahlberg /
Created Apr 29, 2016
Small bot that posts the Bikupan menu of the day to
# CC BY-SA 4.0
import json
import time
import datetime
import requests
from bs4 import BeautifulSoup
johandahlberg /
Created Feb 11, 2016
Quick and dirty performance test of proot at Uppmax
echo "Time in container"
for i in $(seq 1 5)
/usr/bin/time -f "time: %e" proot -S debian-sid --bind=/proj/a2009002/webexport/opendata/HiSeqX_CEPH/CEP-13-3/03-BAM/ samtools mpileup -r 22:1-23096112 /proj/a2009002/webexport/opendata/HiSeqX_CEPH/CEP-13-3/03-BAM/CEP-13-3.clean.dedup.recal.bam 2>&1 > test.pileup | grep time
echo "Time outside container"
for i in $(seq 1 5)
/usr/bin/time -f "time: %e" samtools mpileup -r 22:1-23096112 /proj/a2009002/webexport/opendata/HiSeqX_CEPH/CEP-13-3/03-BAM/CEP-13-3.clean.dedup.recal.bam 2>&1 > test.pileup | grep time
johandahlberg / income_difference.R
Last active Dec 26, 2015
Quick plot of income differences between men and women in the period 1991 to 2013 in Sweden.
View income_difference.R
# Licence:
# Data:
# Downloaded at:
# Sammanräknad förvärvsinkomst, medianinkomst för boende i Sverige den 31/12, tkr efter region, kön, ålder och år
View rwanda_genocide.Rmd
title: Understanding the Rwandan genocide of 1994 through data from the Uppsala Conflict
Data Program
author: "Johan Dahlberg"
date: "October 27, 2015"
output: html_document
``` {r, echo=FALSE, message=FALSE}