This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rawbuffer2JsValue(rawBuffer: RawBuffer): Option[JsValue] = { | |
for { | |
bytes <- rawBuffer.asBytes() | |
} yield { | |
Json.parse(bytes.utf8String) | |
} | |
} | |
def receiveFacebookMessages = withVerifiedPayload { | |
Action (parse.raw) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Licence: | |
# https://creativecommons.org/licenses/by/3.0/ | |
library(ggplot2) | |
library(reshape2) | |
library(dplyr) | |
# Data: | |
# Downloaded at: http://www.statistikdatabasen.scb.se/pxweb/sv/ssd/START__HE__HE0110__HE0110A/SamForvInk2/?rxid=c58583e1-7fc3-418a-9395-0300e138fe7f | |
# Sammanräknad förvärvsinkomst, medianinkomst för boende i Sverige den 31/12, tkr efter region, kön, ålder och år |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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 | |
licence: http://creativecommons.org/licenses/by-sa/3.0/ | |
--- | |
``` {r, echo=FALSE, message=FALSE} |
NewerOlder