Skip to content

Instantly share code, notes, and snippets.

View frgomes's full-sized avatar

Richard Gomes frgomes

View GitHub Profile
@frgomes
frgomes / MatchRegexExtractor.scala
Last active October 18, 2016 23:29
Scala - Extractor using match and regex
object RichText {
val GTDmatch = """GTD[(][0-9A-Za-z\-]+[)]""".r
val NORMAL = """NORMAL[(][0-9]+[)]""".r
val SYNTHETIC_STOP_LIMIT = """SYNTHETIC_STOP_LIMIT[(][0-9]+,[0-9]+[)]""".r
val SYNTHETIC_STOP = """SYNTHETIC_STOP[(][0-9]+[)]""".r
val SYNTHETIC_MARKET_IF_TOUCHED = """SYNTHETIC_MARKET_IF_TOUCHED[(][0-9]+[)]""".r
val NATIVE_STOP_WITH_PROTECTION = """NATIVE_STOP_WITH_PROTECTION[(][0-9]+[)]""".r
val NATIVE_STOP_LIMIT = """NATIVE_STOP_LIMIT[(][0-9]+,[0-9]+[)]""".r
}
@frgomes
frgomes / OrElse.scala
Last active December 17, 2015 11:16
Scala - Partial functions with orElse
import java.io._
val osURL: PartialFunction[Option[String], OutputStream] = {
case Some(name) => new java.io.FileOutputStream(new java.io.File(name))
if(name.contains(":"))
}
val osLocalFile: PartialFunction[Option[String], OutputStream] = {
case Some(name) => new java.io.FileOutputStream(new java.io.File(name))
}
@frgomes
frgomes / ScalaScriptTemplate.scala
Last active December 17, 2015 11:20
Scala script - template script
#!/bin/bash
#-*- mode: scala; -*-
#####
##### NOTE: save this script WITHOUT EXTENSION onto the file system.
#####
launcher=$(which sbt-launch.jar)
if [ -z "$launcher" ] ;then
pushd /tmp
@frgomes
frgomes / Cache.scala
Last active January 5, 2016 17:26
Scala - cache2k with underlying file storage
import net.jcip.annotations.NotThreadSafe
import org.cache2k.impl.ClockProPlusCache
type ImageType = Array[Byte]
class CacheSource(dir: java.io.File)
extends org.cache2k.CacheSource[String, ImageType] {
import java.nio.file.Files
import javax.imageio.ImageIO
@frgomes
frgomes / .gitignore
Last active May 1, 2016 04:23
Git - ~/.gitignore
# Exclude folders
target
# Eclipse
.classpath/
.project/
.settings/
.externalToolBuilders/
*.launch
.target
@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 / 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 / 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 / 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/