Skip to content

Instantly share code, notes, and snippets.

@joprice
joprice / chrome_extension_log.js
Created January 10, 2014 04:02
Log to console when developing chrome devtools extension.
function debug() {
var args = Array.prototype.slice.call(arguments).join(",")
var script = ["console.log(", args, ")"].join('')
chrome.devtools.inspectedWindow.eval(script);
}
@joprice
joprice / playjson-tuple-macro.scala
Last active August 8, 2018 11:01
Play json > tuple 21 macros
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
import play.api.libs.json.{Format, Writes, Reads, OWrites}
object PlayJson{
def reads[A <: AnyRef]: Reads[A] = macro readsImpl[A]
def readsImpl[A <: AnyRef : c.WeakTypeTag](c: Context): c.Expr[Reads[A]] = {
import c.universe._
@joprice
joprice / machinist-bytecode.scala
Created December 19, 2015 04:14
Machinist before/after bytecode
/**
Before:
0: getstatic #19 // Field test/Eq$.MODULE$:Ltest/Eq$;
3: iload_1
4: invokestatic #25 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
7: getstatic #30 // Field test/Eq$intEq$.MODULE$:Ltest/Eq$intEq$;
10: invokevirtual #34 // Method test/Eq$.EqOps:(Ljava/lang/Object;Ltest/Eq;)Ltest/Eq$EqOps;
13: iload_2
// allows converting one class to another by providing missing fields
object convert {
@annotation.implicitNotFound("""
You have not provided enough arguments to convert from ${In} to ${Out}.
${Args}
""")
trait Convertible[Args, In, Out] {
def apply(args: Args, in: In): Out
}
@joprice
joprice / abvsTypeDep.scala
Last active December 21, 2015 22:59 — forked from kailuowang/abvsTypeDep.scala
Abstract Type vs Type parameter
trait AnimalMouth
class Beak extends AnimalMouth
object Test1 {
//================================Generic type works as in the following =======================
trait Animal[Mouth <: AnimalMouth] {
def mouth : Mouth
@joprice
joprice / slick-tsql.conf
Last active January 6, 2016 19:19
Slick compile time query verification
tsql {
driver = "slick.driver.MySQLDriver$"
db {
driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/test"
user = "root"
password = "pass"
}
@annotation.tailrec
def findFileInParents(name: String, dir: File = file(".")): Option[File] = {
lazy val parent = Option(dir.getAbsoluteFile.getParentFile)
val f = dir / name
if (!f.exists) {
println(s"no $f. checking parent")
if (parent.isDefined) findFile(name, parent.get)
else None
} else Some(f)
}
def path[A, B <: AnyRef](name: String, value: A, parent: B): FieldType[(name.type, parent.type), A] =
field[(name.type, parent.type)].apply[A](value)
def emptyPath[A](value: A): FieldType[Nothing, A] = field[Nothing](value)
trait Path[A] {
type Out <: HList
val value: Out

Keybase proof

I hereby claim:

  • I am joprice on github.
  • I am josephprice (https://keybase.io/josephprice) on keybase.
  • I have a public key ASDI8mz2qoozt20aX1FZXjB6ELk1BAewQ_bpwUoGbczsmAo

To claim this, I am signing this object:

@joprice
joprice / git-subtree-basics.md
Created December 29, 2019 21:15 — forked from SKempin/Git Subtree basics.md
Git subtree basics

Git Subtree Basics

If you hate git submodule, then you may want to give git subtree a try.

Background

When you want to use a subtree, you add the subtree to an existing repository where the subtree is a reference to another repository url and branch/tag. This add command adds all the code and files into the main repository locally; it's not just a reference to a remote repo.

When you stage and commit files for the main repo, it will add all of the remote files in the same operation. The subtree checkout will pull all the files in one pass, so there is no need to try and connect to another repo to get the portion of subtree files, because they were already included in the main repo.

Adding a subtree

Let's say you already have a git repository with at least one commit. You can add another repository into this respository like this: