Skip to content

Instantly share code, notes, and snippets.

View matterche's full-sized avatar

Matthias Erche matterche

View GitHub Profile
@matterche
matterche / junit4-templates.xml
Created March 22, 2012 12:16 — forked from hstaudacher/junit4-templates.xml
JUnit4 Templates for Eclipse
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="java" deleted="false" description="" enabled="true" name="setup">${:import(org.junit.Before)}
@Before
public void setUp() {
${cursor}
}</template><template autoinsert="true" context="java" deleted="false" description="" enabled="true" name="teardown">${:import(org.junit.After)}
@After
public void tearDown() {
${cursor}
}</template><template autoinsert="false" context="java-members" deleted="false" description="test method" enabled="true" id="org.eclipse.jdt.ui.templates.test" name="test">${:import(org.junit.Test)}
@Test
@matterche
matterche / AccessLog.scala
Last active July 21, 2016 02:30
Simple access log for Play! 2.3.x app
package globals
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.{Filter, RequestHeader, Result}
import scala.concurrent.Future
object AccessLog extends Filter {
override def apply(next: RequestHeader ⇒ Future[Result])(request: RequestHeader): Future[Result] = {
val start = System.currentTimeMillis()
@matterche
matterche / requests
Last active August 29, 2015 14:23
Use https://github.com/kennethreitz/requests/ to send Json data to a server with self-signed SSL certificate
import requests
requests.packages.urllib3.disable_warnings()
r = requests.post('https://self-signed.cert/',json={"key": "value"}, verify=False)
r.status_code
@matterche
matterche / .pystartup
Last active December 15, 2023 19:21
Enable Python REPL command history and tab completion
# Store this file in ~/.pystartup,
# set "export PYTHONSTARTUP=/home/user/.pystartup"
#
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
# full path to your home directory.
import atexit
import os
import readline
import rlcompleter
#!/usr/bin/env scalas
/***
scalaVersion := "2.11.7"
libraryDependencies += "com.typesafe.play" %% "play-netty-server" % "2.4.1"
*/
import play.core.server._
import play.api.routing.sird._
import play.api.mvc._
@matterche
matterche / EnumUtils.scala
Last active August 29, 2015 14:24 — forked from mikesname/gist:5237809
Play Json enumeration read/write
package enumtest
import play.api.libs.json._
object EnumUtils {
def enumReads[E <: Enumeration](enum: E): Reads[E#Value] = new Reads[E#Value] {
def reads(json: JsValue): JsResult[E#Value] = json match {
case JsString(s) => {
try {
JsSuccess(enum.withName(s))
@matterche
matterche / zsh.md
Last active August 29, 2015 14:24 — forked from tsabat/zsh.md
@matterche
matterche / TableBasedSpec.scala
Created July 16, 2015 13:03
Template for ScalaTest table based property tests
import org.scalatest.prop.PropertyChecks._
import org.scalatest.prop.Tables.Table
import org.scalatest.WordSpec
class MyTableBasedPropertySpec extends WordSpec {
val testData = Table(
("p1", "p2", "p3"),
("1", 2, 3.0),
("4",5,6.0)
)
@matterche
matterche / IntelliJTemplate
Created July 16, 2015 13:27
IntelliJ Idea Template for ScalaTest table based property test
import org.scalatest.prop.PropertyChecks._
import org.scalatest.prop.Tables.Table
import org.scalatest.WordSpec
class MyTableBasedPropertySpec extends WordSpec {
val $testData$ = Table(
("$p1$", "$p2$", "$p3$"),
("1", 2, 3.0),
("4",5,6.0)
)
@matterche
matterche / serialFutures.scala
Created July 20, 2015 15:20
Non-blocking serial execution of futures
// see http://www.michaelpollmeier.com/execute-scala-futures-in-serial-one-after-the-other-non-blocking/
def serialiseFutures[A, B](l: Iterable[A])(fn: A ⇒ Future[B])
(implicit ec: ExecutionContext): Future[List[B]] =
l.foldLeft(Future(List.empty[B])) {
(previousFuture, next) ⇒
for {
previousResults ← previousFuture
next ← fn(next)
} yield previousResults :+ next
}