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
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
[<Test>]
let ``something should something`` () =
some "complicated" (funct "call")
|> shouldMatch (function | This (That _) _ And (These "things") -> ())
@blacktaxi
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
blacktaxi / recodevid.sh
Created August 9, 2015 11:35
Save space on HD phone videos
#!/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 January 7, 2012 19:32
Generating random points inside a circle
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 September 29, 2015 17:06
stack bootstrapper
#!/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 September 29, 2015 17:13
Solution for a classic algo problem
#!./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 January 25, 2012 21:30 — forked from jennifersmith/bells.clj
Cheesy Holiday Music and bell synthesis example
(ns overtone-xmas.bells
( :use [overtone.live]
[overtone.sc.machinery.defcgen]))
;;http://computermusicresource.com/Simple.bell.tutorial.html
(def dull-partials
[
0.56
@blacktaxi
blacktaxi / interpolate.clj
Created January 25, 2012 21:20 — forked from alandipert/interpolate.clj
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 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: 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 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"