Skip to content

Instantly share code, notes, and snippets.

@kindlychung
kindlychung / ffmpeg-install.sh
Last active July 3, 2016 10:08 — forked from clayton/ffmpeg-install.sh
Install FFMPEG on OS X with HomeBrew to convert Mp4 to WebM
# Installation
brew install libvpx
brew install ffmpeg --with-vpx --with-vorbis --with-libvorbis --with-vpx --with-vorbis --with-theora --with-libogg\
--with-libvorbis --with-gpl --with-version3 --with-nonfree --with-postproc --with-libaacplus\
--with-libass --with-libcelt --with-libfaac --with-libfdk-aac --with-libfreetype --with-libmp3lame\
--with-libopencore-amrnb --with-libopencore-amrwb --with-libopenjpeg --with-openssl\
--with-libopus --with-libschroedinger --with-libspeex --with-libtheora --with-libvo-aacenc\
--with-libvorbis --with-libvpx --with-libx264 --with-libxvid --with-libvpx
val pairs = sc.parallelize(List(("aa", 1), ("bb", 2),
("aa", 10), ("bb", 20),
("aa", 100), ("bb", 200)))
/* aggregateByKey is a generalized version of fold, it takes an initial accumulator (here an empty list),
a first lambda function to merge a value to an accumulator, and a
second lambda function to merge two accumulators */
pairs.aggregateByKey(List[Int]())(
(aggr, value) => value +: aggr,
(aggr1, aggr2) => aggr1 ++ aggr2
).foreach(println _)
use std::rc::Rc;
use std::cell;
use std::ops::{Deref, DerefMut};
pub struct SCell<T>(Rc<cell::RefCell<T>>);
pub struct Ref<'a, T: 'a>(cell::Ref<'a, T>);
pub struct RefMut<'a, T: 'a>(cell::RefMut<'a, T>);
impl<T> SCell<T> {
#!/bin/bash
# git-branch-status - this script prints out pretty git branch sync status reports
# * originally by http://github.com/jehiah
# * "s'all good!" message by http://github.com/kd35a
# * ANSI colors by http://github.com/knovoselic
# * formatting, filters, usage, and remotes by http://github.com/bill-auger
read -r -d '' USAGE <<-'USAGE'
% multirust run nightly cargo build
Compiling regex v0.1.30
Compiling libc v0.1.8
Compiling log v0.3.1
Compiling rand v0.3.8
Compiling getopts v0.2.11
Compiling tempfile v0.3.0
Compiling env_logger v0.3.1
Compiling rusti v0.0.1 (file:///l/src/rust/rusti)
@kindlychung
kindlychung / FSM.scala
Created April 11, 2016 07:17 — 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]
@kindlychung
kindlychung / auxpattern.scala
Created January 22, 2016 22:23 — forked from gigiigig/auxpattern.scala
Aux Pattern
import shapeless._
import scalaz._
import Scalaz._
object console extends App {
trait Foo[A] {
type B
def value: B
@kindlychung
kindlychung / Eto sample script
Created January 16, 2016 17:29 — forked from dsyme/Eto sample script
Sample of using the Eto cross-platform GUI framework (https://github.com/picoe/Eto/) with F# (on windows)
#r @"packages\Eto.Forms.1.3.0\lib\net40\Eto.dll"
#r @"packages\Eto.Platform.Windows.1.3.0\lib\net40\Eto.Platform.Windows.dll"
open System
open Eto.Forms
open Eto.Drawing
(defn qc [op & pairs]
(assert (even? (count pairs)))
(fn [coll]
(doseq [[pred msg] (partition 2 pairs)]
(when-not (pred coll)
(throw (IllegalArgumentException. msg))))
(apply op coll)))
(def f1 (qc +
#(= 2 (count %)) "coll must have length 2."
(defn qc [op & pairs]
(assert (even? (count pairs)))
(fn [coll]
(doall
(map (fn [[pred msg]]
(when-not (pred coll)
(throw (IllegalArgumentException. msg))))
(partition 2 pairs))
(apply op coll))))