Skip to content

Instantly share code, notes, and snippets.

Arneball

Block or report user

Report or block Arneball

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 gist:fe41dae3543c5f681c57
object ToFromMap {
implicit def materialize[T]: ToFromMap[T] = macro impl[T]
def impl[T: c.WeakTypeTag](c: Context): c.Expr[ToFromMap[T]] = {
import c.universe._
val wt = weakTypeOf[T]
// Gets the type parameters, eg Holder[T, J] => List(T, J)
val baseTypes = wt.baseClasses.head.asType.typeParams.map{ _.asType.toType }
// Gives a Map(T -> Int, J -> Double) if we are extracting Holder[Int, Double]
val myTypes = baseTypes zip wt.typeArgs toMap;
View Backend.java
package com.example.android2111.app;
import java.util.List;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.converter.gson.GsonConverterFactory
View gist:8541738
import scala.collection.generic.CanBuildFrom
object Batik extends App {
val fun: Int => Option[Int] = {
case 3 => Some(1337)
case 5 => None
case n => Some(n * 3)
}
val mustare = List(1,2,3,4,5).filterMap(fun)
View gist:8399601
/** For every collection that is a sequence, pimp the method groupedSeq */
implicit class GroupedSeq[SEQ[X]<:Seq[X], T](val seq: SEQ[T]) extends AnyVal {
/** Takes a function that maps elems of type T to the grouping kind U
* All sequential elements that has the same group U will be grouped in a SEQ
* Example {{{
* class Person(name: String)
* val people = List(Person("ADAM"), Person("adam"), Person("pelle"))
* people.groupeSeq{ _.name.toUpperCase } => List(List(Person(ADAM), Person(adam)), List(pelle))
* }}}
View gist:8317874
<target name="init" depends="-set-release-mode, -build-setup">
<property
name="scala-library.jar"
value="${scala.dir}/lib/scala-library.jar"
/>
<path id="build.classpath">
<pathelement location="${scala-library.jar}" />
<!--<pathelement location="${your.path}" />-->
<pathelement location="${build.dir}" />
</path>
View gist:8241700
import java.io.{OutputStream, InputStream}
import Skandal._
import scala.annotation.tailrec
import scala.collection.mutable.LazyBuilder
import scala.collection.generic.CanBuildFrom
import scala.collection.mutable.Builder
import scala.collection.SeqLike
import scala.collection.generic.GenericTraversableTemplate
import scala.collection.generic.GenericCompanion
object Mustivar {
@Arneball
Arneball / gist:6364058
Last active Dec 21, 2015
My json parser
View gist:6364058
object Parser {
def main(args: Array[String]): Unit = {
val shit = new JsonParser1()
println{
shit.parseAll(shit.something, """{"nagger": 3, "dicklen": 3.14e2, "slask": null, "arne": "sket", "gammelarray": ["arne", 3, true], "nested": {"apa": true}}""")
}
}
}
class JsonParser1 extends RegexParsers {
View gist:43c48e2bf2d4f4e88fbc
scala> :paste
// Entering paste mode (ctrl-D to finish)
trait Context
object Helper {
def stuff(implicit c: Context) = 3
def stuff_=(i: Int)(implicit c: Context) = ()
// woot
View gist:c003923f417c74b3329c
class Str(val str: String) extends AnyVal {
def isEmpty = str == null || str.isEmpty
def _1 = str.charAt(0)
def _2 = str.substring(1)
}
object Str {
def unapply(str: String): Str = new Str(str)
}
object StrTest {
View gist:0e47ce989aa928afe055
object MySorts extends Ordering.ExtraImplicits {
def mergeSort[T : Ordering](elems: List[T]): List[T] = elems match {
case Nil | _::Nil => elems
case that =>
type L = List[T]
def merge(l1: L, l2: L, acc: L): L = l1 -> l2 match {
case (a::as, b::_) if a < b => merge(as, l2, a::acc)
case (_, b::bs) => merge(l1, bs, b::acc)
case (a::as, _) => merge(as, l2, a::acc)
You can’t perform that action at this time.