Skip to content

Instantly share code, notes, and snippets.

View zoren's full-sized avatar

Søren Sjørup zoren

  • Copenhagen, Denmark
View GitHub Profile
@zoren
zoren / gist:4eb9543395d743670154b7b10059e608
Last active June 19, 2020 09:09 — forked from biggert/gist:6453648
Get a clojure reader using the encoding by the BOM
(ns util
(:require [clojure.java.io :as io])
(:import org.apache.commons.io.input.BOMInputStream
org.apache.commons.io.ByteOrderMark))
(defn bom-reader
"Returns a BOM contextual reader with the proper encoding set (= BOM), defaults to UTF-8"
[input-stream]
(let [bom-array
(into-array [ByteOrderMark/UTF_16LE
@zoren
zoren / hackerrankprelude.fsx
Created December 9, 2016 13:11
My hacker rank prelude for F#
open System
open System.Collections.Generic
let rl = Console.ReadLine
let splsp (s:string) = s.Split([|' '|], StringSplitOptions.RemoveEmptyEntries)
let getTwo (a:_[]) = a.[0], a.[1]
let getThree (a:_[]) = a.[0], a.[1], a.[2]
let callN n action = seq { for i = 1 to n do yield action()} |> Seq.toArray
let iterrl f =
let rec loop () =
let l = rl()
### Keybase proof
I hereby claim:
* I am zoren on github.
* I am zoren (https://keybase.io/zoren) on keybase.
* I have a public key whose fingerprint is 6CB1 901B E1F1 877D E4C6 353A 55FD 41CE 594E 9B0C
To claim this, I am signing this object:
@zoren
zoren / operator precedence parser.swift
Created April 19, 2016 13:15
A implementation of the Operator precedence parser from Wikipedia in Swift 2
// Created by Søren Sjørup on 16/04/16.
// Copyright © 2016 Søren Sjørup. All rights reserved.
import Foundation
indirect enum Exp{
case C(Int)
case Bin(Exp, String, Exp)
}
let rec f _ =
let _ = myignore 1
myignore () // not ok, myignore expects int as argument type
and myignore _ = ()
let rec myignore _ = ()
and f _ =
let _ = myignore 1
myignore () // ok, myignore accepts any type as argument type
@zoren
zoren / gist:5116859
Last active December 14, 2015 16:39
private static Array DownCastArray<TE>( TE[] ar, Type elementType ) {
Array castDown = Array.CreateInstance( elementType, ar.Length );
for ( int i = 0; i < ar.Length; i++ ) {
object value = ar[i];
if ( !elementType.IsInstanceOfType( value ) ) {
throw new ArgumentException( "df" );
}
castDown.SetValue( value, i );
}
return castDown;