Skip to content

Instantly share code, notes, and snippets.

View kjellski's full-sized avatar
🤓
learning every day...

Kjellski kjellski

🤓
learning every day...
View GitHub Profile
@kjellski
kjellski / last_two.fsx
Created March 26, 2015 12:00
last_two
// selfmade :/ not yet...
let rec last_two = function
| [] -> None
| [x] -> None
| x::xs ->
if xs.Length > 1 then
last_two xs
else
Some (x, xs.Head)
let rec last (l: 'a list) : 'a Option =
match l with
| [] -> None
| [x] -> Some x
| x::xs -> last xs
let list = ["a";"a";"a";"a";"b";"c";"c";"a";"a";"d";"d";"e";"e";"e";"e"]
string list
last list
@kjellski
kjellski / compress.fsx
Last active August 29, 2015 14:17
compress
let rec compress = function
| a :: b :: xss ->
if a = b then compress(b::xss) else a:: compress(b::xss)
| smaller -> smaller
let list = ["a";"a";"a";"a";"b";"c";"c";"a";"a";"d";"e";"e";"e";"e"]
string list
compress list
@kjellski
kjellski / flatten.fsx
Last active August 29, 2015 14:17
flatten
type 'a Node =
| One of 'a
| Many of 'a Node list
let testList = [ One "a" ; Many [ One "b" ; Many [ One "c" ; One "d" ] ; One "e" ] ]
let rec flatten (list: 'a Node list) : 'a list =
let rec flatten_nodes acc (node: 'a Node list) : 'a list =
match node with
@kjellski
kjellski / filter.fsx
Last active August 29, 2015 14:17
filter
let rec filter p = function
| [] -> []
| (x::xs) -> if p x then x :: filter p xs
else filter p xs
filter (fun a -> a % 2 = 0) [1..10]
type Expr =
| Zahl of int
| Plus of Expr * Expr
let rec eval sexp =
match sexp with
| Zahl a -> a
| Plus (aexp, bexp) -> eval aexp + eval bexp
eval (Plus(Zahl 3, Plus(Zahl 5, Zahl 2)))
Verifying myself: My Bitcoin username is +kjellski. https://onename.io/kjellski
@kjellski
kjellski / NewtonFractal.cs
Last active October 11, 2021 06:40
LinqPad Compatible Fractal Drawing
/* Idea and clojure from http://nakkaya.com/2010/04/20/fractals-in-clojure-newton-fractal */
Func<Complex, Complex> f1 = c => (c * c * c) - Complex.One;
Func<Complex, Complex> f2 = c => ((c * c * c) - (c * 2)) + 2;
Func<Complex, Complex> f3 = c => new Complex(Math.Sin(c.Real) * Math.Cosh(c.Imaginary),
Math.Cos(c.Real) * Math.Sinh(c.Imaginary));
Func<Complex, Complex> f4 = c => (c * c * c * c) - Complex.One;
double step = 0.000006;
double delta = 0.003;
Tuple<int,int> formDimensions = new Tuple<int,int>(800, 600);
@kjellski
kjellski / keybase.md
Created August 4, 2014 21:44
I am kjellski on keybase.io

Keybase proof

I hereby claim:

  • I am kjellski on github.
  • I am kjellski (https://keybase.io/kjellski) on keybase.
  • I have a public key whose fingerprint is CF95 B30C 2E90 F4F0 B14B F15F 80E6 4797 32D6 6CFA

To claim this, I am signing this object:

@kjellski
kjellski / gist:7766263a02fabb08ee2a
Created July 1, 2014 11:03
KRE_TRACE=1 k web in Home/samples/HelloMvc
root@vagrant-ubuntu-trusty-64:~/src/Home/samples/HelloMvc# KRE_TRACE=1 k web
/root/.kre/packages/KRE-mono45-x86.1.0.0-alpha3-10064/bin/Microsoft.Framework.Runtime.dll Information : 0 : Project root is /root/src/Home/samples/HelloMvc
/root/.kre/packages/KRE-mono45-x86.1.0.0-alpha3-10064/bin/Microsoft.Framework.Runtime.dll Information : 0 : Walking dependency graph for 'HelloMvc .NETFramework,Version=v4.5'.
/root/.kre/packages/KRE-mono45-x86.1.0.0-alpha3-10064/bin/Microsoft.Framework.Runtime.dll Information : 0 : [ProjectReferenceDependencyProvider]: HelloMvc 0.1-alpha-SNAPSHOT
/root/.kre/packages/KRE-mono45-x86.1.0.0-alpha3-10064/bin/Microsoft.Framework.Runtime.dll Information : 0 : [NuGetDependencyResolver]: Microsoft.AspNet.Diagnostics 0.1-alpha-build-0682, Microsoft.AspNet.Hosting 0.1-alpha-build-0572, Microsoft.AspNet.Mvc 0.1-alpha-build-1268, Microsoft.AspNet.Server.WebListener 0.1-alpha-build-0520, Microsoft.AspNet.FeatureModel 0.1-alpha-build-0444, Microsoft.AspNet.Http 0.1-alpha-build-0444, Microsoft.A