Skip to content

Instantly share code, notes, and snippets.

View praeclarum's full-sized avatar

Frank A. Krueger praeclarum

View GitHub Profile
@praeclarum
praeclarum / NoiseAnimation.fs
Created December 20, 2014 19:10
A little iOS app that shows a noisy square moving in a field of noise
namespace NoiseAnimation
#nowarn "64"
open System
open UIKit
open Foundation
open CoreGraphics
[<AutoOpen>]
@praeclarum
praeclarum / AutoLayout.fs
Last active April 27, 2020 11:07
AutoLayout wrapper to make creating constraints in F# easier
module Praeclarum.AutoLayout
open System
#if __IOS__
open Foundation
open UIKit
type NativeView = UIView
#else
open Foundation
@praeclarum
praeclarum / EasyLayout.fs
Last active August 23, 2020 09:52
EasyLayout makes writing auto layout code in Xamarin.iOS F# easier.
module EasyLayout
open System
open System.Drawing
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open Microsoft.FSharp.Quotations.DerivedPatterns
open MonoTouch.Foundation
open MonoTouch.UIKit
@praeclarum
praeclarum / Speaker.cs
Created June 26, 2014 19:08
Easy way to asynchronously speak some text on iOS with C#
using System;
using MonoTouch.AVFoundation;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Praeclarum
{
/// <summary>
/// Easy way to asynchronously speak some text.
/// <code>
@praeclarum
praeclarum / PlayMidi.cs
Created May 27, 2014 03:53
Shows how to play MIDI files and dynamically create songs on iOS using C# (Xamarin)
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using MonoTouch;
using MonoTouch.AudioToolbox;
using MonoTouch.AudioUnit;
using MonoTouch.CoreFoundation;
using MonoTouch.CoreMidi;
using MonoTouch.Foundation;
@praeclarum
praeclarum / TileSticher.cs
Created April 10, 2014 22:28
Downloads and stitches map tiles
using System;
using System.Net;
using System.IO;
using Gdk;
namespace TileSticher
{
class App
{
public static int Main (string[] args)
@praeclarum
praeclarum / ObservableTableViewController.cs
Created April 7, 2014 16:57
This is my UITableViewController with DataSource property that listens for INotifyCollectionChanged
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace Praeclarum.UI
{
@praeclarum
praeclarum / SingleThreaded.cs
Created January 25, 2014 23:36
Use single threaded blocking code from your UI
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Concurrent;
namespace Praeclarum
{
/// <summary>
/// Wraps a value and only allows access to it using a single thread
/// of execution (see SingleThreadQueue).
@praeclarum
praeclarum / EasyLayoutExample.cs
Last active June 16, 2018 12:26
Here is an example of using my [EasyLayout](https://gist.github.com/praeclarum/6225853) library. Note the use of <= and >=, these are very difficult to write in old fashioned (frame-based) layout code. Also note the extension method GetMidY() that emulates Center.Y. You can also use GetBaseline() that works for baseline-aware views.
ContentView.ConstrainLayout (() =>
border.Frame.Top == ContentView.Frame.Top &&
border.Frame.Height == 0.5f &&
border.Frame.Left == ContentView.Frame.Left &&
border.Frame.Right == ContentView.Frame.Right &&
nameLabel.Frame.Left == ContentView.Frame.Left + hpad &&
nameLabel.Frame.Right == ContentView.Frame.GetMidX () - 5.5f &&
nameLabel.Frame.Top >= ContentView.Frame.Top + vpad &&
@praeclarum
praeclarum / backup.m
Last active December 24, 2015 07:29
Reverse engineered iCloud backup time estimator
- (NSTimeInterval)remainingUbiquitousBackupTime
{
return 3 * 60;
}