Skip to content

Instantly share code, notes, and snippets.

View giabao's full-sized avatar

Bùi Việt Thành giabao

View GitHub Profile
scalaVersion := "2.11.4"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.0"
libraryDependencies += "org.scala-lang" % "scalap" % scalaVersion.value
InputKey[Unit]("scalap") := {
import complete.DefaultParsers._
val classes = spaceDelimited("<class names>").parsed
val classpath = "-classpath" :: (fullClasspath in Compile).value.map(_.data).mkString(":") :: Nil
@alternegro
alternegro / gist:4568362
Created January 18, 2013 20:43
play scala soap client plus json transformation
def interday(symbol:String, range:String) = Action {request =>
Async {
WS.url("http://api.sproutwerks.com/api/TimeSeries/TimeSeries.svc").withHeaders(CONTENT_TYPE -> "application/soap+xml").post(ChartRequests.interdayRequest(symbol, range)).map { response =>
Ok(timeSeriesToJson(range.toUpperCase, response.xml, noFilter, timeLabeler(range))).as(JSON)
}
}
}
def intraday(symbol:String) = Action {request =>
Async {
class Cell[T](value: T) {
var other: T = value
}
object Test {
def g[T, U](x: T, y: U) = if (util.Random.nextBoolean) x else y
def f1 = g(1f, "abc")
def f2 = g(1: Byte, "abc")
def f3 = g(f1, f2)
/*** Inferred return types:
The Union Type Quiz
===================
0. Please give your typing approach an intuitive name:
Consistent, Unified Subsumption
1. Please describe the guiding principle of your typing approach in one sentence:
@rbranson
rbranson / crossdomain.conf
Created February 3, 2011 21:13
nginx Flash XML policy server
# Add this to your nginx.conf under http { }
server {
listen 843;
server_name localhost;
location / {
rewrite ^(.*)$ /crossdomain.xml;
}
@kevinwright
kevinwright / scaladays2014.md
Last active March 8, 2018 20:25
Scaladays 2014 slides

As compiled by Kevin Wright a.k.a @thecoda

(executive producer of the movie, and I didn't even know it... clever huh?)

please, please, please - If you know of any slides/code/whatever not on here, then ping me on twitter or comment this Gist!

This gist will be updated as and when I find new information. So it's probably best not to fork it, or you'll miss the updates!

Monday June 16th

@redox
redox / base.html.haml
Last active May 16, 2020 13:13
Algolia extends HipChat to customer support
#chat-box.ubuntu.hidden-xs
.closed
.pull-right
= link_to_function content_tag(:i, nil, class: 'glyphicon glyphicon-chevron-up').html_safe, 'chat.show()'
.m-l-small
= link_to_function 'Chat with us', 'chat.show()'
.opened{style: 'display: none'}
.header
.pull-right
= link_to_function content_tag(:i, nil, class: 'glyphicon glyphicon-plus-sign').html_safe, 'chat.maximize()', class: 'maximize', style: 'display: none'
@wfaler
wfaler / scalap_extracted.scala
Created April 10, 2011 18:24
Scalap signature reading extracted into what will be a util class for Scala 2.9 reflection compatibility.
package com.recursivity.commons.bean.scalap
import scala.tools.scalap.scalax.rules.scalasig._
import tools.scalap._
import scalax.rules.scalasig.ClassFileParser.{ConstValueIndex, Annotation}
import reflect.generic.ByteCodecs
import java.io.{StringWriter, ByteArrayOutputStream, PrintStream}
@mbedward
mbedward / gist:6e3dbb232bafec0792ba
Last active September 26, 2021 14:08
Scala macro to convert between a case class instance and a Map of constructor parameters. Developed by Jonathan Chow (see http://blog.echo.sh/post/65955606729/exploring-scala-macros-map-to-case-class-conversion for description and usage). This version simply updates Jonathan's code to Scala 2.11.2
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
trait Mappable[T] {
def toMap(t: T): Map[String, Any]
def fromMap(map: Map[String, Any]): T
}
object Mappable {
@jorgeortiz85
jorgeortiz85 / PrivateMethodCaller.scala
Created April 7, 2011 15:41
Calling private methods in Scala
// Usage:
// p(instance)('privateMethod)(arg1, arg2, arg3)
class PrivateMethodCaller(x: AnyRef, methodName: String) {
def apply(_args: Any*): Any = {
val args = _args.map(_.asInstanceOf[AnyRef])
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass)
val parents = _parents.takeWhile(_ != null).toList
val methods = parents.flatMap(_.getDeclaredMethods)
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found"))