Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔

Sergey Yavnyi blacktaxi

🤔
View GitHub Profile
@blacktaxi
blacktaxi / ShouldMatch.fs
Created Jul 5, 2015
Poor man's complex pattern matching in F# tests
View ShouldMatch.fs
let shouldMatch f x =
try f x |> ignore
with :? MatchFailureException as e ->
failwithf "Did not expect %A" x
[<Test>]
let ``something should something`` () =
some "complicated" (funct "call")
|> shouldMatch (function | This (That _) _ And (These "things") -> ())
@blacktaxi
blacktaxi / StructVsDU.fs
Last active Aug 29, 2015
F#: DU vs Struct performance
View StructVsDU.fs
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
blacktaxi / recodevid.sh
Created Aug 9, 2015
Save space on HD phone videos
View recodevid.sh
#!/bin/bash
# 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: encodevid.sh [path]
QUALITY=26.0
INPATH=$1
@blacktaxi
blacktaxi / gist:1575749
Created Jan 7, 2012
Generating random points inside a circle
View gist:1575749
import random
random.seed()
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
blacktaxi / stack
Created Sep 29, 2015
stack bootstrapper
View stack
#!/bin/bash
which stack > /dev/null
if [ $? -ne 0 ]; then
if [ ! -f ./.stack/stack ]; then
OS=`uname`
if [ $OS == "Darwin" ]; then
STACK_URL=https://github.com/commercialhaskell/stack/releases/download/v0.1.3.1/stack-0.1.3.1-x86_64-osx.gz
elif [ $OS == "Linux" ]; then
STACK_URL=https://github.com/commercialhaskell/stack/releases/download/v0.1.3.1/stack-0.1.3.1-x86_64-linux.gz
else
@blacktaxi
blacktaxi / Carrotland.hs
Created Sep 29, 2015
Solution for a classic algo problem
View Carrotland.hs
#!./stack
-- 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
blacktaxi / bells.clj
Created Jan 25, 2012 — forked from jennifersmith/bells.clj
Cheesy Holiday Music and bell synthesis example
View bells.clj
(ns overtone-xmas.bells
( :use [overtone.live]
[overtone.sc.machinery.defcgen]))
;;http://computermusicresource.com/Simple.bell.tutorial.html
(def dull-partials
[
0.56
View interpolate.clj
;;; ENVIRONMENTAL IMPACT STATEMENT
;;;
;;; This program was written on recycled memory.
;;; No cons cells were created.
;;;
(ns interpolate
(:use [clojure.walk :only (postwalk)]))
(defmacro s
@blacktaxi
blacktaxi / main.clj
Created Jan 25, 2012 — forked from lynaghk/main.clj
Cassowary constraint solver in ClojureScript
View main.clj
;;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: http://dev.clojure.org/jira/browse/CLJS-114
;;Fix applied here: https://github.com/lynaghk/clojurescript/tree/114-refer-clojure-exclude
(:refer-clojure :exclude [+ - =])
@blacktaxi
blacktaxi / haskjure.clj
Created Jan 26, 2012 — forked from djhworld/haskjure.clj
useful haskell functions that I can't seem to find in clojure
View haskjure.clj
(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"