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 / 1930.hs
Created October 28, 2015 01:46
Ivan's car™
#!/usr/bin/env stack
-- stack --resolver lts-3.11 --install-ghc runghc --package array --package containers
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap.Strict as IM
import qualified Data.Map.Strict as M
import qualified Data.Sequence as Seq
import Data.Sequence ((<|), (><))
@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 / 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 / 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 / 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 / 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 / ninject-dynamic-get.cs
Last active December 24, 2015 11:59
Ninject ConstructorArguments as named parameters to a dynamic invoke
namespace Ninject
{
public static class NinjectExtensions
{
private class DynKernel : DynamicObject
{
private readonly IKernel kernel;
public DynKernel(IKernel inner)
{
@blacktaxi
blacktaxi / signextlib.bat
Created September 17, 2013 10:30
Shell script to sign a .NET assembly.
@echo off
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe" -q -vf "%1" > NUL
if ERRORLEVEL 1 goto NOT_SIGNED
:SIGNED
echo Already signed: %~nx1
goto END
:NOT_SIGNED
@blacktaxi
blacktaxi / markdown_block.rb
Created August 30, 2013 08:54
Inline markdown blocks in Jekyll layouts/pages.
module Jekyll
class MarkdownBlock < Liquid::Block
def initialize(tag_name, text, tokens)
super
end
require "kramdown"
def render(context)
content = super
"#{Kramdown::Document.new(content).to_html}"
end
open System.IO
open System.Net
let wc = new WebClient()
let trainingSetFile = Path.Combine( __SOURCE_DIRECTORY__, "trainingSet.csv")
File.WriteAllText(trainingSetFile,
contents = wc.DownloadString("http://brandewinder.blob.core.windows.net/public/trainingsample.csv")
)