Skip to content

Instantly share code, notes, and snippets.

@kindlychung
kindlychung / 0_reuse_code.js
Last active August 29, 2015 14:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console

fireplace

  • cpr => (require ... :reload)
  • cpR => (require ... :reload-all)

Evaluation

  • :Eval (clojure code) => runs (clojure code) in repl
  • cpp => evaluate inn-most expessions under cursor
  • cp<movement> => evaluate text described by <movement>
  • cqp => opens quasi-repl
  • cqc => quasi-repl command line window
(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))))
(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."
@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
@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 / 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]
% 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)
#!/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'
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> {