Skip to content

Instantly share code, notes, and snippets.

View sniperliu's full-sized avatar

Liu Hao sniperliu

View GitHub Profile
#[derive(Debug, PartialEq)]
struct BinaryTree<T> {
root: Option<Box<Node<T>>>,
}
#[derive(Debug, PartialEq)]
struct Node<T> {
value: T,
left: Option<Box<Node<T>>>,
right: Option<Box<Node<T>>>,
@sniperliu
sniperliu / .block
Last active August 15, 2017 02:15
vega signal example
license: mit
@sniperliu
sniperliu / .block
Last active June 16, 2017 04:19
Vega-Lite update example
license: mit
@sniperliu
sniperliu / spec_parsing.clj
Created December 12, 2016 09:39 — forked from thegeez/spec_parsing.clj
Parsing with clojure.spec for the Advent of Code challenge
(ns net.thegeez.advent.spec-parsing
(:require [clojure.string :as str]
[clojure.spec :as s]
[clojure.spec.gen :as gen]
[clojure.test.check.generators :as tgen]))
;; Dependencies:
;; [org.clojure/clojure "1.9.0-alpha14"]
;; [org.clojure/test.check "0.9.0"]
;; Advent of Code is a series of code challenges in the form of an advent
{-# LANGUAGE BangPatterns #-}
module SimpleExampleMvar where
import Control.Concurrent
import Control.Monad
import System.Environment(getArgs)
import Data.Int
import Text.Printf
import Control.Exception
import System.CPUTime
-- modified version of @__josejuan__
;; warm up: balancing
=> (s/def ::balanced
(s/* (s/cat :open #{'<} :children ::balanced :close #{'>})))
:user/balanced
=> (s/conform ::balanced '[< < > < > > < >])
[{:open <, :children [{:open <, :close >} {:open <, :close >}], :close >} {:open <, :close >}]
=> (s/conform ::balanced '[< < > < < > > > < >])
[{:open <, :children [{:open <, :close >} {:open <, :children [{:open <, :close >}], :close >}], :close >} {:open <, :close >}]
;; infix to prefix
(ns clj-spec.fish
(:require [schema.core :as schema]
[clojure.spec :as spec]
[clojure.spec :as s]))
;; just beginning
;; Schema does this
(def Data
"A schema for a nested data type"
(ns clj-bt.bencoding
(:require [clojure.string :as s]
[the.parsatron :as p :refer [defparser let->> >>]]))
;; decoding
(defparser zero [] (>> (p/char \0) (p/always 0)))
(defparser non-zero [] (p/token #{\1 \2 \3 \4 \5 \6 \7 \8 \9}))
(defparser positive []
(let->> [fst (non-zero)