Skip to content

Instantly share code, notes, and snippets.

View erip's full-sized avatar

Elijah Rippeth erip

  • Fairfax, VA
View GitHub Profile
@erip
erip / build.sbt
Last active December 22, 2017 13:25
My attempt to shade guava with coursier
import sbt.Keys._
lazy val commonSettings = Seq(
name := "shading-issue",
version := "0.1",
scalaVersion in ThisBuild := "2.11.8"
)
lazy val `dummy` = (project in file("."))
.settings(commonSettings: _*)
@erip
erip / Example.scala
Created January 2, 2018 14:10
`withClient` example
import com.lightbend.lagom.scaladsl.testkit.ServiceTest._
private def withDefaultClient(testCode: (MyService) => Any): Unit = {
withServer(ServiceTest.defaultSetup) { ctx =>
new MyApplication(ctx) with LocalServiceLocator {
// whatever your Application Cake should look like...
}
} { server =>
// Client for your service
val client = server.serviceClient.implement[MyService]
@erip
erip / test_parses.py
Last active February 4, 2018 22:23
Parsing tests for Python.
from unittest import TestCase
from nltk import FeatureEarleyChartParser, load, word_tokenize
class ParserTestCase(TestCase):
def setUp(self):
self.grammar = load("file:{0}".format("./grammar.fcfg"))
self.parser = FeatureEarleyChartParser(self.grammar, trace=0)
def __should_parse(self, sentence):
@erip
erip / OpenId.scala
Last active February 19, 2019 09:18
OpenID authentication with Lagom
import com.lightbend.lagom.scaladsl.api.transport.Forbidden
import com.lightbend.lagom.scaladsl.api.{Service, ServiceCall}
import com.lightbend.lagom.scaladsl.server.PlayServiceCall
import play.api.libs.openid.{OpenIdClient, UserInfo}
import play.api.mvc.EssentialAction
import scala.concurrent.{ExecutionContext, Future}
/**
* A trait which will provide OpenID authentication when provided with an OpenID client.
@erip
erip / build.sbt
Last active July 24, 2018 20:47
Weird scoverage issue
// Tried with 2.11.8, 2.12.3, 2.12.4
scalaVersion in ThisBuild := "2.12.3"
// Tried with scoverage 1.5.1, 1.6.0-M3
// Tried with sbt 1.0.4, 1.1.1
lazy val commonSettings = Seq(
parallelExecution in Test := false,
organization := "com.example.blah"
)
@erip
erip / UserServiceImpl.scala
Created August 2, 2018 14:07
An example of if in flatMap
override def registerUser(): ServiceCall[requests.RegisterUser, UUID] = ServerServiceCall { req =>
repository.emailHasBeenRegistered(req.email).flatMap { beenRegistered =>
logger.debug(s"Email ${req.email} has been registered? $beenRegistered")
if (!beenRegistered) {
val id = UUID.randomUUID()
logger.debug(s"Registering user $id")
userEntityFor(id)
.ask(InternalRegisterCommand(id, req.firstName, req.lastName, req.email, req.password))
} else {
logger.warn(s"Email ${req.email} has already been registered")
@erip
erip / faust_app.py
Last active October 7, 2018 17:13
My tricky faust problem
import faust
from faust import TopicT
import asyncio
class MyBlockingService(faust.Service):
def __init__(self, success_topic: TopicT, *args):
super().__init__(*args)
self.success_topic = success_topic
@erip
erip / simple_test.pony
Created December 23, 2018 16:08
A simple property test
use "ponytest"
use "ponycheck"
class iso AdditionAssociativeProperty is UnitTest
fun name(): String => "u8/addition-associative"
fun apply(h: TestHelper)? =>
let g = recover val Generators.zip3[U8, U8, U8](
Generators.u8(), Generators.u8(), Generators.u8()
@erip
erip / law.pony
Last active December 24, 2018 00:30
use "ponytest"
use "ponycheck"
use ".."
interface val _TestSemigroupAssociativity[T] is UnitTest
fun semigroup(): Semigroup[T]
fun t(): String
@erip
erip / farsi_issue.html
Created December 30, 2019 19:14
RTL issue with displaCy
<!DOCTYPE html>
<html lang="fa">
<head>
<title>displaCy</title>
</head>
<body style="font-size: 16px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; padding: 4rem 2rem; direction: rtl">
<figure style="margin-bottom: 6rem">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="fa" id="6cc1af9f34a64a4592fa784da0aa419f-0" class="displacy" width="3650" height="887.0" direction="rtl" style="max-width: none; height: 887.0px; color: #000000; background: #ffffff; font-family: Arial; direction: rtl">
<text class="displacy-token" fill="currentColor" text-anchor="middle" y="797.0">