Skip to content

Instantly share code, notes, and snippets.

View EdgeCaseBerg's full-sized avatar
📉
Wondering why Github added statuses instead of something useful

Ethan Eldridge EdgeCaseBerg

📉
Wondering why Github added statuses instead of something useful
View GitHub Profile
@EdgeCaseBerg
EdgeCaseBerg / AutomaticTestsWithReflection.scala
Last active January 8, 2016 21:47
How to automatically test if you're providing appropriate matches if you need to parse string to some case objects without reflection in your code. Pretty fun stuff I think
package com.github.edgecaseberg.test {
import scala.reflect.runtime.universe
import scala.reflect.runtime.universe.typeOf
import scala.util.Random
import org.scalatest._
trait ParsingTest extends FlatSpec with Matchers {
val random = new Random()
def randomCase(s: String): String = {
@EdgeCaseBerg
EdgeCaseBerg / logmonitor.sh
Last active December 15, 2015 20:57
Log Monitor
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage: ./monitor.sh /my/log/file.log [sleep time (s)]"
echo "Will output a dot for each second monitored that there are no changes"
echo "Will stop script once no changes are detected to log file"
fi
if [ $# -eq 1 ]; then
LOGFILE=$1
@EdgeCaseBerg
EdgeCaseBerg / logmonitor.sh
Created December 15, 2015 16:21
Log Monitor
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage: ./monitor.sh /my/log/file.log"
fi
if [ $# -eq 1 ]; then
LOGFILE=$1
fi
@EdgeCaseBerg
EdgeCaseBerg / requestbuilding.patch
Created September 17, 2015 16:04
spray.httpx.RequestBuilding
- Options("/generate/imageId/OneToOne/800").withHeaders(List(HttpHeaders.Origin(Seq(HttpOrigin("http", Host("allowedhost.com")))))) ~> myroute ~> check {
+ Options("/generate/imageId/OneToOne/800") ~> addHeader("Origin", "http://allowedhost.com") ~> myroute ~> check {
Above is scalatest spray example of adding headers to request
@EdgeCaseBerg
EdgeCaseBerg / requestbuilding.patch
Created September 17, 2015 16:04
spray.httpx.RequestBuilding
- Options("/generate/imageId/OneToOne/800").withHeaders(List(HttpHeaders.Origin(Seq(HttpOrigin("http", Host("allowedhost.com")))))) ~> myroute ~> check {
+ Options("/generate/imageId/OneToOne/800") ~> addHeader("Origin", "http://allowedhost.com") ~> myroute ~> check {
@EdgeCaseBerg
EdgeCaseBerg / break-the-compiler.scala
Last active August 29, 2015 14:25
Example on how to break the scala compiler
class testCase() {
val smallFile = Array[Byte](-1,-40,-1,-32,0,16,74,70,73,70,0,1,1,1,0,109,0,109,0,0,-1,-37,0,67,0,8,6,6,7,6,5,8,7,7,7,9,9,8,10,12,20,13,12,11,11,12,25,18,19,15,20,29,26,31,30,29,26,28,28,32,36,46,39,32,34,44,35,28,28,40,55,41,44,48,49,52,52,52,31,39,57,61,56,50,60,46,51,52,50,-1,-37,0,67,1,9,9,9,12,11,12,24,13,13,24,50,33,28,33,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,-1,-64,0,17,8,1,0,1,0,3,1,34,0,2,17,1,3,17,1,-1,-60,0,31,0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,-1,-60,0,-75,16,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125,1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,-127,-111,-95,8,35,66,-79,-63,21,82,-47,-16,36,51,98,114,-126,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,-125,-124,-123,-122,-121,-120,-119,-118,-110,-109,-108,-107,-106,-105,-1
// Using vars, lots of local mutation
def getThemVar(th:Throwable)={
var now=th
var li=List[Throwable](now)
var cause=now.getCause
while (cause!=null){
li=cause::li
now=cause
cause=now.getCause
}
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@EdgeCaseBerg
EdgeCaseBerg / HttpApp.scala
Created May 12, 2015 20:42
Example for multi controller routing in Akka Spray
import akka.io.IO
import akka.actor._
import akka.pattern.ask
import akka.util.Timeout
import spray.http._
import spray.can.Http
import spray.routing._
import spray.routing.RequestContext
import spray.routing.directives.CachingDirectives._
@EdgeCaseBerg
EdgeCaseBerg / faster.py
Last active August 29, 2015 14:20
Python shell of checking to see which one is faster, addition of strings or interpolation
>>> import dis
>>> def addStr(s):
... return ">" + s + "<"
...
>>> dis.dis(addStr)
2 0 LOAD_CONST 1 ('>')
3 LOAD_FAST 0 (s)
6 BINARY_ADD
7 LOAD_CONST 2 ('<')
10 BINARY_ADD