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 EdgeCaseBerg

📉
Wondering why Github added statuses instead of something useful
View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / gist:783ddbddf79da9c34a00
Created January 11, 2016 16:38
Get log from stdout without a log file
1. look up process id,
2. cd to /proc/{id}/fd
3. tail -f 1
@EdgeCaseBerg
EdgeCaseBerg / versionReport.sbt
Created January 25, 2016 16:10
sbt build task to see dependencies in a project.
//https://groups.google.com/forum/#!topic/simple-build-tool/rcPh-lWbDtk
lazy val versionReport = TaskKey[String]("version-report")
// Add this setting to your project.
versionReport <<= (externalDependencyClasspath in Compile, streams) map {
(cp: Seq[Attributed[File]], streams) =>
val report = cp.map {
attributed =>
attributed.get(Keys.moduleID.key) match {
case Some(moduleId) => "%40s %20s %10s %10s".format(
@EdgeCaseBerg
EdgeCaseBerg / LoggerContext for Play.scala
Last active February 3, 2016 16:13
Playing with string contexts and what one could do with them.
import play.Logger
scala> implicit class LogHelper(val sc: StringContext) extends AnyVal {
| def log(args: Any*): Unit = {
| Logger.info(sc.s(args:_*))
| println(sc.s(args:_*))
| }}
defined class LogHelper
scala> log"Hello $hi"
@EdgeCaseBerg
EdgeCaseBerg / BasicAuthFilter.scala
Last active April 28, 2016 21:53 — forked from dk8996/BasicAuthFilter.scala
Basic Auth Filter for Play Framework
import com.typesafe.scalalogging.slf4j.Logging
import sun.misc.BASE64Decoder
import play.api.mvc._
import scala.concurrent.Future
import play.mvc.Results._
import play.api.libs.concurrent.Execution.Implicits.defaultContext
object BasicAuthFilter extends Filter with Logging {
private lazy val unauthResult = Results.Unauthorized.withHeaders(("WWW-Authenticate",
"Basic realm=\"myRealm\""))