Skip to content

Instantly share code, notes, and snippets.

View pedrofurla's full-sized avatar

Pedro Furlanetto pedrofurla

View GitHub Profile
@pedrofurla
pedrofurla / chrome
Created July 8, 2016 15:42
Bash/AppleScripts to open or reload chrome
open /Applications/Google\ Chrome.app --args --allow-file-access-from-files --unlimited-quota-for-files
@pedrofurla
pedrofurla / Tmp.scala
Last active June 11, 2016 15:06
Where String#+ comes from?
object Tmp {
"zzz" ++ "kkk" // Fails with -Yno-predef
// after typer the above is scala.this.Predef.augmentString("zzz").++[Char, String](scala.this.Predef.augmentString("kkk"))(scala.this.Predef.StringCanBuildFrom);
"aaa"+new Object() // Doesn't fail ever!
// after typer the above is "aaa".+(new java.this.lang.Object());
// Why didn't `+` desugar to something else?
new Object() + "aaa" // Fails with -Yno-predef
function *gen(x) {
var i = yield(x + 1);
console.log(i, typeof i);
var y = 2 * i;
var z = yield (y/3);
return x + y +z
}
var g = gen(5)
@pedrofurla
pedrofurla / sbt-prompt-git.scala
Last active November 21, 2015 06:43
Nice looks and git info into the sbt shell
addCommandAlias("git", "; sh git")
commands ++= Seq(
Command.args("sh", "<shell command>") { (state, args) =>
// using script here maintains ansi colors, see http://stackoverflow.com/a/13587964/467390
val ret = ("script -q /dev/null " ++ args.mkString(" ")) !;
state
}
)
def title[A <: { def name:String }](a:A):A = { print(a.name); a}
suppose we have Company(name:String, address:String), Person(name:String, age:Int)
title(person).age
title(company).address
title(person).address // error
{-
From: https://gist.github.com/pedrofurla/12516a6998ca39520b14
Re-interpretation of the problem:
- An imaginary room of size N x M,
- Contains a robot that can move one unit (of the above scale) at a time.
- Attempting to cross the boundaries of the room has no effect.
- Certain positions contains patchs of dirty. If the robot gets to that position it is cleansed.
Program organization:
@pedrofurla
pedrofurla / gist:7860cc38d0acc4e929d3
Created January 16, 2015 18:58
Stylish CSS to improving the "readability" of the online Purescript by Example book
/* To be used with the online version of Purescript by Example https://leanpub.com/purescript/read */
#read-online { color:black }
#read-online .read { width:auto }
.sidebar {
position: absolute;
margin-left: 450px; /* this is to make sure the book add stays visible, probably there is more reliable way of doing this */
}
@pedrofurla
pedrofurla / gist:6d852f856f3182a3104f
Created October 10, 2014 04:36
Sketch of a bunch of studies topics
title
Functional Programming

Fundamentals

Conception, evolution, and application of functional programming languages

The algebra of types

@pedrofurla
pedrofurla / gist:f5e3da72188acae96bd5
Created June 2, 2014 19:17
Custom config and task for multiple initialCommands in SBT Scala console
val hconfig = config("hconfig").extend(Compile)
lazy val hconsole = taskKey[Unit]("hconsole")
lazy val destroySchema = taskKey[Unit]("destroySchema")
hconsole := (console in hconfig).value
val slickperf = project.in(file(".")).
configs(hconfig).
settings(inConfig(hconfig)(Defaults.configTasks) : _*)
@pedrofurla
pedrofurla / gist:752108dc505c52fd2657
Created May 3, 2014 17:01
Start and stop H2 DB server from SBT
val startH2Task = TaskKey[Unit]("start-h2", "Starts H2 DB")
val stopH2Task = TaskKey[Unit]("stop-h2", "Stops H2 DB")
val h2tasks:Seq[Setting[_]] = Seq(startH2Task := {
org.h2.tools.Server.createTcpServer().start();
org.h2.tools.Server.createWebServer().start // this starts the "web tool"
}, stopH2Task :={
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9092","",true,true);
} )