Skip to content

Instantly share code, notes, and snippets.

View ShaneDelmore's full-sized avatar

Shane Delmore ShaneDelmore

View GitHub Profile
@ShaneDelmore
ShaneDelmore / downloadBambooArtifact.sc
Created August 9, 2016 20:29
Download an artifact on OSX from Atlassian Bamboo
#!/usr/bin/env amm
//Requirements:
// This only runs on OSX as it uses OSX Keychain to store your Bamboo login credentials
// Tested with Ammonite 0.7.0
import ammonite.ops._
import $ivy.`org.scalaj::scalaj-http:2.2.0`, scalaj.http._
import $ivy.`org.json4s::json4s-native:3.4.0`, org.json4s._, native.JsonMethods._
import java.net.SocketTimeoutException
implicit val formats = DefaultFormats //Bring default json formats into scope
implicit val wd = cwd //set working directory to current working directory
@ShaneDelmore
ShaneDelmore / QueryExecutor.scala
Last active September 19, 2016 00:18
Slick Typeclass
import slick.dbio.{DBIOAction, NoStream}
import com.shane.db.models.Slick3PostgresDriver.api.Database
import scala.concurrent.Future
trait QueryExecutor {
def run[R](action: DBIOAction[R, NoStream, Nothing]): Future[R]
def runExtended[R](action: DBIOAction[R, NoStream, Nothing]): Future[R] = run(action)
}
@ShaneDelmore
ShaneDelmore / regex.scala
Created September 29, 2016 20:36
regex extractors
val testString =
"""
|PROJECT_DIR=$(cd "${BASH_SOURCE[0]%/*}" && pwd -P)/../..
|
|MAINCLASS=com.business.service.MyService
|
|
|exec java $JAVA_OPTS -cp "$PROJECT_DIR/my_service/target/scala-2.11/classes" "$MAINCLASS" "$@"
|
""".stripMargin
@ShaneDelmore
ShaneDelmore / canBuildFrom.scala
Created September 29, 2016 20:42
CanBuildFrom example
import scala.collection._
import scala.collection.generic._
implicit class TraversableLikeOps[+T, +Repr](val seq: SeqLike[T, Repr]) {
def zipWithNext[That](implicit c: CanBuildFrom[Repr, (T, T), That]): That = {
val builder = c(seq.repr)
val is = seq.toIndexedSeq
builder ++= is.zip(is.drop(1))
builder.result
}
@ShaneDelmore
ShaneDelmore / hardToFormat.scala
Created October 16, 2016 05:42
Scalafmt returns illegal start of simple expression on this
//scalafmt returns: error: illegal start of simple expression
def validStringLength(min: Int, max: Int): String => Boolean = {
s =>
val len: Int = s.length
(min <= len) && (len <= max)
}
//scalafmt is fine with this
def validStringLength(min: Int, max: Int): String => String => Boolean =
s => {
@ShaneDelmore
ShaneDelmore / RedundantParens.scala
Last active November 10, 2016 03:02
RemoveRedundantParens
package org.scalafmt.rewrite
import scala.meta.Tree
import scala.meta._
import scala.meta.tokens.Token.{LeftBrace, LeftBracket, LeftParen, RightBrace, RightBracket, RightParen}
//Do we need a way to link certain types together (meta or scalafmt)?
object Balanced {
val matchingParens: (Token => Boolean, Token => Boolean) =
(_.is[LeftParen], _.is[RightParen])
@ShaneDelmore
ShaneDelmore / SafeString.scala
Created December 15, 2016 20:04
Summon special strings
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary._
trait Tagged[+V, +T]
type @@[+V, +T] = V with Tagged[V, T]
trait Safe
implicit val arbitrarySafeString: Arbitrary[String @@ Safe] =
Arbitrary(
@ShaneDelmore
ShaneDelmore / Import.scala
Created January 17, 2017 06:12
More fun with scalatest
package scalafix.util
import scala.collection.immutable.Seq
import scala.meta._
import syntax._
object Import {
def remove(prefix: String, term: String): PartialFunction[Tree, Tree] = {
case b @ q"{ ..$stats }" /* verify targeted term exists */ =>
val newStats: Seq[Stat] = stats.collect {

Keybase proof

I hereby claim:

  • I am shanedelmore on github.
  • I am shanedelmore (https://keybase.io/shanedelmore) on keybase.
  • I have a public key ASCjD-4yeo9keUkltfhWRotlwERtREAP0_piYbBacvX0cAo

To claim this, I am signing this object:

@ShaneDelmore
ShaneDelmore / clippy.json
Created April 27, 2017 21:08
Imclipitly Matryoshka
{
"version":"0.1",
"advices":[{
"error":{
"type":"notAMember",
"what":"value step",
"notAMemberOf":".*Partial.*"
},
"text":"You may need to import matryoshka.instances._",
"library":{