Skip to content

Instantly share code, notes, and snippets.

View johandahlberg's full-sized avatar

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
@johandahlberg
johandahlberg / lunchbot.py
Created April 29, 2016 16:04
Small bot that posts the Bikupan menu of the day to
# CC BY-SA 4.0
# http://creativecommons.org/licenses/by-sa/4.0/
import json
import time
import datetime
import requests
from bs4 import BeautifulSoup
@johandahlberg
johandahlberg / plotCoverageProportions.R
Created June 27, 2013 16:35
A R script to plot cumulative coverage based on GATK DepthOfCoverage output files. Not very pretty, but perhaps helpful to somebody.
library(ggplot2)
setwd("<my working directory>")
removeExtraLine <- function(x) {
x[,2:length(x)]
}
createInitialDataset <- function(x, sampleName) {
extraLineRemoved <- t(removeExtraLine(x))
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
case class FacebookPostingMessages(`object`: String, entry: Seq[MessagePostEntry]) {
def messages(): Seq[Message] = {
entry.flatMap(_.messaging).map(_.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)
class SHA1VerificationService {
private val secret = "<your key>"
private def computeSHA1Hash(payloadBytes: Array[Byte], secret: String): String = {
val HMAC_SHA1_ALGORITHM = "HmacSHA1"
val secretKeySpec = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), HMAC_SHA1_ALGORITHM)
val mac = Mac.getInstance(HMAC_SHA1_ALGORITHM)
mac.init(secretKeySpec)
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
def rawbuffer2JsValue(rawBuffer: RawBuffer): Option[JsValue] = {
for {
bytes <- rawBuffer.asBytes()
} yield {
Json.parse(bytes.utf8String)
}
}
def receiveFacebookMessages = withVerifiedPayload {
Action (parse.raw) {
@johandahlberg
johandahlberg / performance_test.sh
Created February 11, 2016 14:04
Quick and dirty performance test of proot at Uppmax
echo "Time in container"
for i in $(seq 1 5)
do
/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
done
echo "Time outside container"
for i in $(seq 1 5)
do
/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
johandahlberg / prepareReference.sh
Created November 5, 2013 16:18
A script for preparing a reference for running with piper on Uppmax.
#!/bin/bash -l
#SBATCH -A b2010028
#SBATCH -p core
#SBATCH -n 2
#SBATCH -t 10:00:00
#SBATCH -J prepare_ref
#SBATCH -o prepare_ref-%j.out
#SBATCH -e prepare_ref-%j.error
# Author: Johan D