Skip to content

Instantly share code, notes, and snippets.

View blacktaxi's full-sized avatar
russia is a terrorist state, russians are a terrorist nation

Serhii Yavnyi blacktaxi

russia is a terrorist state, russians are a terrorist nation
View GitHub Profile
blacktaxi / ShouldMatch.fs
Created July 5, 2015 00:26
Poor man's complex pattern matching in F# tests
let shouldMatch f x =
try f x |> ignore
with :? MatchFailureException as e ->
failwithf "Did not expect %A" x
let ``something should something`` () =
some "complicated" (funct "call")
|> shouldMatch (function | This (That _) _ And (These "things") -> ())
blacktaxi / StructVsDU.fs
Last active August 29, 2015 14:25
F#: DU vs Struct performance
module Test =
open System
open System.Diagnostics
let bench (actionFactory : unit -> (unit -> unit),
minIterations : int option) =
let minIterations = defaultArg minIterations 1
let properTime (action : unit -> unit)
blacktaxi /
Created August 9, 2015 11:35
Save space on HD phone videos
# this script recodes phone videos to a lower bitrace encoding to save space.
# phones typically encode at a very high bitrate because they don't have enough
# CPU power to do a more compressed encoding in real time.
# generally this recoding does not affect perceived video quality.
# USAGE: [path]
blacktaxi / gist:1575749
Created January 7, 2012 19:32
Generating random points inside a circle
import random
import math
def rnd(_from=0, _to=1): return _from + random.random() * (_to - _from)
def rectangle_random(W=2, H=2):
return (rnd(0, W), rnd(0, H))
blacktaxi / stack
Created September 29, 2015 17:06
stack bootstrapper
which stack > /dev/null
if [ $? -ne 0 ]; then
if [ ! -f ./.stack/stack ]; then
if [ $OS == "Darwin" ]; then
elif [ $OS == "Linux" ]; then
blacktaxi / Carrotland.hs
Created September 29, 2015 17:13
Solution for a classic algo problem
-- stack --resolver lts-2.14 --install-ghc runghc --package hspec --package QuickCheck
module Carrotland where
import Data.List (sort, find, partition)
import Data.Maybe (fromMaybe)
type Point = (Integer, Integer)
-- projection of a segment on X and Y axes, respectively
blacktaxi / bells.clj
Created January 25, 2012 21:30 — forked from jennifersmith/bells.clj
Cheesy Holiday Music and bell synthesis example
(ns overtone-xmas.bells
( :use []
(def dull-partials
blacktaxi / interpolate.clj
Created January 25, 2012 21:20 — forked from alandipert/interpolate.clj
;;; This program was written on recycled memory.
;;; No cons cells were created.
(ns interpolate
(:use [clojure.walk :only (postwalk)]))
(defmacro s
blacktaxi / main.clj
Created January 25, 2012 21:23 — forked from lynaghk/main.clj
Cassowary constraint solver in ClojureScript
;;Using the Cassowary constraint solver from ClojureScript
;;This demo shows using multimethods for readable constraint syntax using +, -, and =.
;;Output is a row of circles with random radii spaced so that the space between their boundaries is uniform.
(ns c2.main
;;refer-clojure :exclude is currently broken in ClojureScript master
;;Ticket open:
;;Fix applied here:
(:refer-clojure :exclude [+ - =])
blacktaxi / haskjure.clj
Created January 26, 2012 13:49 — forked from djhworld/haskjure.clj
useful haskell functions that I can't seem to find in clojure
(defn group [xs]
"splits its sequence argument into a list of lists of equal, adjacent elements."
(partition-by identity xs))
(defn zip [xs ys]
"makes a list of vector tuples, each tuple containing elements of both sequences occuring at the same position"
(map vector xs ys))
(defn lines [str]
"For a given string, split it into a vector using a newline terminator as a delimiter"