Skip to content

Instantly share code, notes, and snippets.

Anton Kropp devshorts

Block or report user

Report or block devshorts

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View zip.go
package packaging
import (
"archive/zip"
"io"
)
type PackageContents struct {
Data io.Reader
FileName string
View Encodings
/**
* Encoding for "A is not a subtype of B"
* @note original credit: https://gist.github.com/milessabin/c9f8befa932d98dcc7a4
*/
trait NotTypeOf[A, B]
trait NotTypeImplicits {
// Uses ambiguity to rule out the cases we're trying to exclude
implicit def allowedType[A, B] : A NotTypeOf B = null
implicit def typeSuperTypeOfInvalid[A, B >: A] : A NotTypeOf B = null
View Simple Edit Distance
object EditDistance {
def within(s1: String, s2: String, n: Int = 1): Boolean = {
if (s1 != s2 && Math.abs(s1.length - s2.length) > 1) {
return false
}
var s1Idx = 0
var s2Idx = 0
def withinN() = Math.abs(s1Idx - s2Idx) <= n
View Slick MySQL bigInteger jdbc profile
trait BigIntegerTypesComponent extends RelationalTypesComponent {
self: JdbcProfile =>
implicit def bigIntType = new BigIntegerJdbcType
implicit val bigIntSetParam = new SetParameter[BigInteger] {
override def apply(v1: BigInteger, v2: PositionedParameters): Unit = v2.setObject(v1, java.sql.Types.BIGINT)
}
class BigIntegerJdbcType extends DriverJdbcType[BigInteger] with NumericTypedType {
View BitGroup wrapper
object BitGroup {
def zero(max: Int): BitGroup = {
val bytesRequired = max / 8
new BitGroup(new Array[Byte](bytesRequired + 1), max)
}
def filled(max: Int): BitGroup = {
val bytesRequired = max / 8
View Git sync organiation
#!/usr/bin/env ruby
require 'octokit'
require 'pp'
Octokit.auto_paginate = true
org=ARGV[0]
client = Octokit::Client.new(:access_token => "#{ENV['GIT_ACCESS_TOKEN']}")
View Finatra vs jackson anyvals
case class StringAnyVal @JsonCreator()(@(JsonValue@getter) value: String) extends AnyVal
case class AnyValHolder(anyVal: StringAnyVal)
class Jackson extends FlatSpec with Matchers {
val finatra = FinatraObjectMapper.create().objectMapper
val jackson = {
val o = new ObjectMapper with ScalaObjectMapper
o.registerModule(DefaultScalaModule)
View gist:443791d8eeb15099a66b9f7c3b1da313
package tests
import com.twitter.finagle.builder.ClientBuilder
import com.twitter.finagle.http.Http
import com.twitter.finatra.httpclient.RequestBuilder
import com.twitter.util.{Await, Future}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}
View working client
// finagle 6.1.33
class ClientObjectTests extends FlatSpec with Matchers with BeforeAndAfterAll {
"A client" should "be closeable" in {
val client =
ClientBuilder()
.dest("localhost:1")
.codec(Http())
.hostConnectionLimit(1)
.build()
View Failing finagle client
@RunWith(classOf[JUnitRunner])
class ClientObjectTests extends FlatSpec with Matchers with BeforeAndAfterAll {
"A client" should "be closeable" in {
val client =
ClientBuilder()
.dest("localhost:1")
.codec(Http())
.hostConnectionLimit(1)
.build()
You can’t perform that action at this time.