Skip to content

Instantly share code, notes, and snippets.

View praeclarum's full-sized avatar

Frank A. Krueger praeclarum

View GitHub Profile
@praeclarum
praeclarum / AlgorithmW.fs
Last active March 19, 2024 17:44
Algorithm W - or Hindley-Milner polymorphic type inference - in F#
module AlgorithmW
// HINDLEY-MILNER TYPE INFERENCE
// Based on http://catamorph.de/documents/AlgorithmW.pdf
// (Now at http://web.archive.org/web/20170704013532/http://catamorph.de/documents/AlgorithmW.pdf)
type Lit =
| LInt of int
| LBool of bool
@praeclarum
praeclarum / Script.fs
Created August 26, 2015 06:37
Scripting language in F#
module k
(*
type TypeIdent = string
type TypeExpr = name:string? (string | TypeIdent | Or TypeExpr TypeExpr | And TypeExpr)
type TypeDecl = Type string TypeExpr
@praeclarum
praeclarum / PieChartLayer.cs
Created August 2, 2015 03:15
CA Layer example
using System;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using MonoTouch.CoreAnimation;
using System.Drawing;
namespace Presentation.AnimationPresentation
{
class PieChartLayer : CALayer
{
@praeclarum
praeclarum / Seq.swift
Last active August 29, 2015 14:24
Some function and SequenceType extensions that I found missing in Swift 2
//
// Seq.swift
//
// Created by Frank A. Krueger on 7/8/15.
// Copyright © 2015 Krueger Systems, Inc. All rights reserved.
// MIT Licensed
//
import Foundation
@praeclarum
praeclarum / Script.swift
Last active November 26, 2020 22:31
A little scripting language written in Swift. It supports first class functions (closures) and variable mutation. This code includes the AST, the interpreter, and a JavaScript parser.
//
// Script.swift
//
// Created by Frank A. Krueger on 6/28/15.
// Copyright © 2015 Krueger Systems, Inc. All rights reserved.
//
import Foundation
enum Val {
@praeclarum
praeclarum / ArrayDiff.swift
Last active January 8, 2021 06:10
A generic diffing operation that can calculate the minimal steps needed to convert one array to another. It can be used to generate standard diffs, or it can be used more creatively to calculate minimal UI updates.
//
// ArrayDiff.swift
//
// Created by Frank A. Krueger on 6/30/15.
// Copyright © 2015 Krueger Systems, Inc. All rights reserved.
// License: MIT http://opensource.org/licenses/MIT
//
import Foundation
2015-06-08 19:30:34.539 Mocast[717:131208] DATA /var/mobile/Containers/Data/Application/D2784AE1-D4E4-4555-9CB7-D576E6470AD4/Documents/Mocast.sqlite
2015-06-08 19:30:34.562 Mocast[717:131208] ERROR: System.DllNotFoundException: sqlite3
at (wrapper managed-to-native) SQLite.SQLite3:Open (byte[],intptr&,int,intptr)
at SQLite.SQLiteConnection..ctor (System.String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks) [0x00066] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:219
at SQLite.SQLiteConnection..ctor (System.String databasePath, Boolean storeDateTimeAsTicks) [0x00000] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:181
at Mocast.MocastStorage..ctor () [0x00089] in /Users/fak/Dropbox/Projects/Mocast/Mocast/Mocast/MocastStorage.cs:49
at Mocast.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x0002a] in /Users/fak/Dropbox/Projects/Mocast/Mocast/AppDelegate.cs:58
ERROR: System.DllNotFoundException: sqlite3
at (wrapper
@praeclarum
praeclarum / gist:70631f41b678cd4e380b
Created June 9, 2015 02:08
Mocast Crash on iOS 9
Mocast[650] <Notice>: WARNING: The runtime version supported by this application is unavailable.\^J
Mocast[650] <Notice>: Using default runtime: v4.0.30319\^J
Mocast[650] <Notice>: * Assertion at ../../../../../mono/mono/mini/aot-runtime.c:4607, condition `amodule->info.tramp_page_size == psize' not met\^J
Mocast[650] <Notice>: \^JNative stacktrace:\^J\^J
Mocast[650] <Notice>: 0 Mocast 0x022f41c7 mono_handle_native_sigsegv + 238\^J
Mocast[650] <Notice>: 1 Mocast 0x022f8095 sigabrt_signal_handler + 104\^J
Mocast[650] <Notice>: 2 libsystem_platform.dylib 0x37fce88b _sigtramp + 42\^J
Mocast[650] <Notice>: 3 libsystem_pthread.dylib 0x37fd394f pthread_kill + 62\^J
Mocast[650] <Notice>: 4 libsystem_c.dylib 0x37ed5fe9 abort + 108\^J
Mocast[650] <Notice>: 5 Mocast 0x0239bd4d monoeg_log_default_handler + 112\^J
@praeclarum
praeclarum / Parser.fs
Last active August 29, 2015 14:16
Parser for a little language in F#
module Parser =
type Position =
{
Code : string
Index : int
}
let ws p =
if p.Index >= p.Code.Length then p
@praeclarum
praeclarum / PinnedArray2.fs
Created March 4, 2015 15:15
PinnedArray2 for passing 2D arrays to native code
type PinnedArray2 (array : float[,]) =
let h = GCHandle.Alloc (array, GCHandleType.Pinned)
let ptr = Marshal.UnsafeAddrOfPinnedArrayElement(array, 0)
member this.Ptr = NativePtr.ofNativeInt<float>(ptr)
interface IDisposable with
member this.Dispose () = h.Free ()