Skip to content

Instantly share code, notes, and snippets.

View frgomes's full-sized avatar

Richard Gomes frgomes

View GitHub Profile
@frgomes
frgomes / DynamicMixIn.scala
Last active April 29, 2016 13:49
Scala - Dynamically mixin a trait to an instance
/** This is a marker trait intended to provide independence of FIX version. */
trait SecurityListLike extends quickfix.Message
object SecurityListLike {
implicit def mixin(o: Mixin) = o.o
def ::(o: quickfix.Message) = new Mixin(o)
final class Mixin private[SecurityListLike](val o: quickfix.Message) extends SecurityListLike {
import quickfix.field.MsgType
require(o.getHeader.getString(MsgType.FIELD) == MsgType.SECURITY_LIST)
}
@frgomes
frgomes / .hgignore
Last active May 1, 2016 04:23
Mercurial - ~/.hgignore
syntax: glob
# General files and folders
tmp/
target/
target_sbt/
.cache/
.history
# Eclipse
@frgomes
frgomes / .gitignore
Last active May 1, 2016 04:23
Git - ~/.gitignore
# Exclude folders
target
# Eclipse
.classpath/
.project/
.settings/
.externalToolBuilders/
*.launch
.target
@frgomes
frgomes / FSM.scala
Created May 4, 2016 12:05 — forked from knutwalker/FSM.scala
Simple Encoding of a purely functional Finite State Machine using Scala and scalaz
package example.statemachine
import scalaz.{State, Scalaz}, Scalaz._
object FSM {
def apply[I, S](f: PartialFunction[(I, S), S]): FSM[I, S] =
new FSM((i, s) => f.applyOrElse((i, s), (_: (I, S)) => s))
private def states[S, O](xs: List[State[S, O]]): State[S, List[O]] =
xs.sequence[({type λ[α]=State[S, α]})#λ, O]
@frgomes
frgomes / jitsi.list
Last active May 21, 2016 20:20
Debian - /etc/apt/sources.list, /etc/apt/preferences, /etc/apt/sources.list.d/llvm.list
#/etc/apt/sources.list.d/jitsi.list
# $ wget -qO - https://download.jitsi.org/nightly/deb/unstable/archive.key | sudo apt-key add -
deb http://download.jitsi.org/deb unstable/
@frgomes
frgomes / init.el
Last active June 10, 2016 09:33
Emacs - ~/.emacs.d/init.el
(require 'package) ;; You might already have this line
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)
(global-set-key "\C-cd" 'zeal-at-point)
;(add-to-list 'zeal-at-point-mode-alist '(rust-mode . "rust"))
@frgomes
frgomes / CustomOrdering.scala
Last active June 14, 2016 17:09
Scala - Custom ordering
case class Employee(id: Int, firstName: String, lastName: String)
object Employee {
// Note that because `Ordering[A]` is not contravariant, the declaration
// must be type-parametrized in the event that you want the implicit
// ordering to apply to subclasses of `Employee`.
implicit def orderingByName[A <: Employee]: Ordering[A] =
Ordering.by(e => (e.lastName, e.firstName))
val orderingById: Ordering[Employee] = Ordering.by(e => e.id)
@frgomes
frgomes / ChainingTraits.scala
Last active June 29, 2016 06:42
Scala - Chaining traits
trait Irrelevant {}
trait Base {
def text: String = "Base"
def enter: () => Any =
() => {
println("enter: Some logic")
}
@frgomes
frgomes / JsonWrite.scala
Last active July 4, 2016 11:20
Scala - Serialize case class as JSON / Easily print case class contents.
// Jupyter Scala kernel magic
classpath.add("org.json4s" % "json4s-native_2.11" % "3.4.0")
import org.json4s._
import org.json4s.native.Serialization
implicit val formats = Serialization.formats(NoTypeHints)
case class Subject(article: String, page: Int)
case class Speaker(name: String, age: Int, subject: Subject)
val speaker = Speaker("John Doe", 45, Subject("Doing It Yourself", 200))
@frgomes
frgomes / xorg.conf.dual-identical-monitors
Last active July 15, 2016 22:48
Debian - /etc/X11/xorg.conf
Section "ServerLayout"
Identifier "aticonfig Layout"
Screen 0 "aticonfig-Screen[0]-0" 0 0
EndSection
Section "Files"
EndSection
Section "Module"
EndSection