Skip to content

Instantly share code, notes, and snippets.

Paul Kinsky pkinsky

Block or report user

Report or block pkinsky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pkinsky
pkinsky / f2048
Last active Aug 29, 2015
functional 2048
View f2048
//todo: use vector, scala 2:10 generic extractors. Currently using 2.9, so List has better pattern matching support
type Row = List[Option[Int]]
def shiftR(r: Row): Row = r.foldRight(Nil: Row){
case (None, acc) => acc
case (Some(x), Some(a)::as) if a == x => Some(a + x)::as
case (Some(x), acc) => Some(x)::acc
}.padTo(4, None)
@pkinsky
pkinsky / Scala Trie
Last active Aug 29, 2015
Scala Trie
View Scala Trie
case class Trie(v: Option[String], m: Map[Char, Trie])
def addInner(t: Trie, s: List[Char], p: String): Trie = s match {
case c::cs => Trie(t.v, t.m.updated(c, addInner(t.m.getOrElse(c, Trie(Some(p + c), Map.empty)), cs, p + c) ))
case Nil => t
}
def add(t: Trie, s: String): Trie = addInner(t, s.toList, "")
def findInner(t: Trie, s: List[Char]): Option[String] = s match {
@pkinsky
pkinsky / throttle.scala
Created Dec 3, 2014
Throttle a flow using Akka Stream's new FlowGraph DSL
View throttle.scala
val rate = 200 millis
def throttled[T]: Flow[T, T] = {
val tickSource = TickSource(rate, rate, () => () )
val zip = Zip[T, Unit]
val in = UndefinedSource[T]
val out = UndefinedSink[T]
PartialFlowGraph{ implicit builder =>
import FlowGraphImplicits._
in ~> zip.left ~> Flow[(T,Unit)].map{ case (t, _) => t } ~> out
View install-ghc.md

How to install latest GHC 7.8.4 + cabal 1.22 on intel edison w/ ubi linux

ghc

ubilinux prerequisites

# for untar later
apt-get install bzip2
# probably all needed
apt-get install freeglut3 freeglut3-dev -y
@pkinsky
pkinsky / flyweight.scala
Created Apr 1, 2015
Flyweight in Scala
View flyweight.scala
/*
run as a script using `scala flyweight.scala`
expected output:
Serving CoffeeFlavour(Espresso) to table 121
Serving CoffeeFlavour(Cappuccino) to table 121
Serving CoffeeFlavour(Frappe) to table 552
Serving CoffeeFlavour(Espresso) to table 96
Serving CoffeeFlavour(Cappuccino) to table 3
Serving CoffeeFlavour(Espresso) to table 3
Serving CoffeeFlavour(Frappe) to table 3
View fib.scala
def fibonacci(number: Int): Int = {
assert(number >= 0)
@annotation.tailrec def inner(prev: Int, curr: Int, n: Int): Int =
if (n < number) inner(curr, prev + curr, n + 1)
else curr
if (number == 0) 0
else if (number == 1) 1
else inner(0, 1, 1)
@pkinsky
pkinsky / fish-prompt.fish
Last active Nov 24, 2015 — forked from gak/fish-prompt.sh
My custom fish prompt code explained at http://geraldkaszuba.com/tweaking-fish-shell/
View fish-prompt.fish
# https://gist.github.com/oliversalzburg/a57a8b82dd8ec245f985
function _common_section
printf $c1
printf $argv[1]
printf $c0
printf ":"
printf $c2
printf $argv[2]
printf $argv[3]
@pkinsky
pkinsky / pusher.scala
Last active Aug 11, 2016 — forked from gre/pusher.scala
Using Pusher API with Play framework in scala for publishing events
View pusher.scala
//send messages via Pusher API in play 2.4
import play.api.libs.json.{ Writes, Json }
import play.api.libs.ws.{ WSResponse, WSClient }
import play.api.libs.ws.ning.NingWSClient
import java.security.MessageDigest
import java.math.BigInteger
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import scala.concurrent.{ ExecutionContext, Future }
@pkinsky
pkinsky / function_vs_partial_function.scala
Last active Feb 4, 2016
{n => n + 1} and {case n => n +1} are almost but not quite the same thing
View function_vs_partial_function.scala
scala> val f: Function[Int, Int] = { n => n + 1 }
f: Function[Int,Int] = <function1>
scala> val f: Function[Int, Int] = { case n => n + 1 }
f: Function[Int,Int] = <function1>
scala> val pf: PartialFunction[Int, Int] = { n => n + 1 }
<console>:10: error: type mismatch;
found : Int => Int
required: PartialFunction[Int,Int]
View vimrc
" install plugins. (requires running :PlugInstall)
" Specify a directory for plugins (for Neovim: ~/.local/share/nvim/plugged)
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
Plug 'altercation/vim-colors-solarized'
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/syntastic'
You can’t perform that action at this time.