Skip to content

Instantly share code, notes, and snippets.

View pedrofurla's full-sized avatar

Pedro Furlanetto pedrofurla

View GitHub Profile
@pedrofurla
pedrofurla / postgres_queries_and_commands.sql
Created April 9, 2020 02:15 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@pedrofurla
pedrofurla / Main-Decompiled.java
Created September 12, 2017 04:34 — forked from rahulmutt/Main-Decompiled.java
Polymorphism in Eta via Type Erasure
public static class id extends Function {
public Closure enter(StgContext context) {
// context.R(2) is the first argument of the function
// All id simply does is evaluate the argument -
// it cannot do much more!
return context.R(2).evaluate(context);
}
public int arity() { return 1; }
}
@pedrofurla
pedrofurla / git-branches-by-commit-date.sh
Created November 4, 2016 18:59 — forked from jasonrudolph/git-branches-by-commit-date.sh
List remote Git branches and the last commit date for each branch. Sort by most recent commit date.
# Credit http://stackoverflow.com/a/2514279
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r
@pedrofurla
pedrofurla / IO.scala
Created August 12, 2016 15:40 — forked from jdegoes/IO.scala
A pedagogical implementation of the IO monad in Scala in 14 LOC
case class IO[A](unsafePerformIO: () => A) {
def map[B](ab: A => B): IO[B] = IO(() => ab(unsafePerformIO()))
def flatMap[B](afb: A => IO[B]): IO[B] =IO(() => afb(unsafePerformIO()).unsafePerformIO())
def tryIO(ta: Throwable => A): IO[A] =
IO(() => IO.tryIO(unsafePerformIO()).unsafePerformIO() match {
case Left(t) => ta(t)
case Right(a) => a
})
}
object IO {
trait EntityBase {
def id: String
}
trait Repository {
type Entity <: EntityBase
def get(id: String): Option[Entity]
}
/**
* Created by pedrofurla on 26/03/14.
*/
package slicks.docs
import slicks.docs.dao.{Entity, IdentifiableTable, CrudComponent, Profile}
case class User(id: Option[Long], first: String, last: String) extends Entity[Long]
trait UserComponent extends CrudComponent { outer: Profile =>
@pedrofurla
pedrofurla / Function1.scala
Created November 13, 2012 04:05 — forked from tonymorris/Function1.scala
scala Function1
object Function1Stuff {
def flatMap[T, A, B]: Function1[T, A] => (A => Function1[T, B]) => Function1[T, B] =
sys.error("todo")
}
trait Bar { def bar(msg:String):Unit }
trait Qux extends Bar {
abstract override def bar(msg:String="Qux Says Hello") = {
super.bar(msg)
println("qux: " + msg)
}
}
class Foo extends Bar {