Skip to content

Instantly share code, notes, and snippets.

View WilsonGramer's full-sized avatar

Wilson Gramer WilsonGramer

View GitHub Profile
Robot : type {
name :: Text
}
[context]
robot :: Robot
robot : crash "`robot` not initialized"
with-robot : syntax {
with-robot 'name 'body -> with (robot : Robot { name : 'name }) 'body
@WilsonGramer
WilsonGramer / syntax.rs
Created February 13, 2023 19:12
Syntax rule expansion with support for repetitions
use std::collections::{HashMap, HashSet};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Expression {
Name(&'static str),
Number(i32),
Variable(&'static str),
List(Vec<Expression>),
Block(Vec<Vec<Expression>>),
}
@WilsonGramer
WilsonGramer / RollingScrollView.swift
Created November 30, 2022 04:06
SwiftUI scroll view whose contents roll in from the bottom like the iOS 16 notification center
import SwiftUI
import ViewExtractor // https://github.com/GeorgeElsham/ViewExtractor
let wallpaperURL = URL(string: "https://9to5mac.com/wp-content/uploads/sites/6/2022/09/iPhone-14-Pro-wallpaper-3.jpeg?quality=100&strip=all")!
struct ContentView: View {
@ScaledMetric(relativeTo: .largeTitle) var clockFontSize = 96
@State private var timeIsVisible = true
@State private var notificationsAreVisible = false
use std::collections::{HashMap, HashSet};
#[derive(Debug)]
pub struct Context<Id> {
substitutions: HashMap<TypeVariable, Type<Id>>,
exists: Vec<Type<Id>>,
next_var: u32,
}
#[derive(Debug)]
show : external "internal" "show" :: Text -> ()
-- A work-in-progress recreation of Typing the Technical Interview
-- (https://aphyr.com/posts/342-typing-the-technical-interview) in what will
-- eventually be Wipple's type system!
--
-- 'type' creates marker types. For example, you can define 'Phantom' as either:
-- given (some A) in Phantom : type A
-- Phantom : type (some _)
--
-- 'some' creates invariant type parameters
--
@WilsonGramer
WilsonGramer / install.sh
Last active June 18, 2021 19:44
Cross-compile Swift 5.4 for arm64 on x64 Ubuntu
set -ex
# Add arm64 packages to apt database
# WARNING: This overwrites the sources.list entirely! If you have custom sources,
# add [arch=amd64] to them instead and just add the [arch=arm64] lines yourself
sudo bash -c 'cat <<EOF > /etc/apt/sources.list
deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
@WilsonGramer
WilsonGramer / parse.py
Last active May 20, 2020 03:37
Parse parentheses, brackets and braces, ensuring they are balanced and in the right order
LeftParen = '('
RightParen = ')'
LeftBracket = '['
RightBracket = ']'
LeftBrace = '{'
RightBrace = '}'
class Group(object):
def __init__(self):
self.exprs = []
import Foundation
public struct IntermediateStrideThrough<Number: Strideable, Amount: Comparable & SignedNumeric> {
let from: Number
let by: Amount
public init(from: Number, by: Amount) {
self.from = from
self.by = by
}
@WilsonGramer
WilsonGramer / baseconverter.py
Created August 19, 2018 18:49
baseconverter.py
from math import log, ceil, floor
digit_refs = list('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-/:;()$&@".,?!\'[]{}#%^*+=_\\|~<>€£¥•')
# Inverts the index relative to the length (of an array) provided.
# Example: (3, 0) => 2
def rev(len, index):
return len - 1 - index
class Number: