Skip to content

Instantly share code, notes, and snippets.

View praeclarum's full-sized avatar

Frank A. Krueger praeclarum

View GitHub Profile
@praeclarum
praeclarum / Layout.cs
Created March 16, 2013 05:23
A C# syntax for NSLayoutConstraints.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using MonoTouch.UIKit;
namespace Async.iOS
{
public static class Layout
{
@praeclarum
praeclarum / Database.fs
Created February 16, 2022 17:11
An immutable database with reference entities, cascading deletes, undo buffers, serialization, and reactive variables
namespace Neural
type Id = System.String
type Id<'T> =
| Id of Id
override this.ToString () = match this with Id id -> id
type IEntity =
abstract References : Id seq with get
abstract DeleteReference : Id -> IEntity option
@praeclarum
praeclarum / build-net6-apple.yml
Last active January 29, 2022 15:35
GitHub jobs to build and deploy .NET 6 apps multi-targeting iOS and macOS
name: Build and Test
on:
pull_request:
push:
branches:
- main
schedule:
- cron: '13 13 * * *'
@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 / NNControl.c
Created October 28, 2021 19:19
C code implementing the neural network that I trained to control my balancing robot
#include "NNControl.h"
#include <math.h>
extern const float nncontrol_dense_74_weights0[320]; // (5, 64)
extern const float nncontrol_dense_74_weights1[64]; // (64,)
extern const float nncontrol_dense_75_weights0[4096]; // (64, 64)
extern const float nncontrol_dense_75_weights1[64]; // (64,)
extern const float nncontrol_dense_76_weights0[64]; // (64, 1)
static const float tf_math_multiply_69_Mul_0_const0[1] = {0};
@praeclarum
praeclarum / MinimalOoui.cs
Created June 6, 2021 17:26
Minimal Ooui application
using System;
using Ooui;
namespace MinimalOoui
{
class Program
{
static Element CreateUI()
{
@praeclarum
praeclarum / read_rotary.c
Created April 16, 2021 18:07
Arduino code to get clean values from even the noisiest and silliest rotary encoder
// From https://www.best-microcontroller-projects.com/rotary-encoder.html
static uint8_t prevNextCode = 0;
static uint16_t store=0;
int8_t read_rotary() {
static int8_t rot_enc_table[] = {0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0};
prevNextCode <<= 2;
if (digitalRead(RIGHT_PIN)) prevNextCode |= 0x02;
@praeclarum
praeclarum / Rainfall.md
Created April 7, 2021 15:04
Rainfall using Calca

Rainfall in Gallons

I wonder how much water falls on land throughout the year? We can use a [rainfall database][rdb] to find out how much it rains in Seattle and then use Calca's unit conversion support to help us determine that.

land area = 0.25 acre

avg annual precip = 36.15 inch / year

daily rain accumulation

= avg annual precip * land area

@praeclarum
praeclarum / JamesSubsMatrix.ino
Created March 28, 2021 20:17
Arduino code to print James' subscriber count
// ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include "secrets.h"
const char* ssid = SECRET_SSID; // SSID of local network
const char* password = SECRET_PASSWORD; // Password on network
const long UPDATE_INTERVAL_MILLIS = 10L * 60L * 1000L;
//const long UPDATE_INTERVAL_MILLIS = 1L * 1000L;
@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