Skip to content

Instantly share code, notes, and snippets.

@hirrolot
hirrolot / CoC-60.ml
Created April 13, 2025 13:40
Calculus of Constructions in 60 lines of OCaml
let discard _a b = b
let rec pp lvl = function
| `Lam f -> "" ^ pp (lvl + 1) (f (`Go lvl)) ^ ")"
| `Pi (a, f) -> "" ^ pp lvl a ^ "." ^ pp (lvl + 1) (f (`Go lvl)) ^ ")"
| `Appl (m, n) -> "(" ^ pp lvl m ^ " " ^ pp lvl n ^ ")"
| `Ann (m, a) -> "(" ^ pp lvl m ^ " : " ^ pp lvl a ^ ")"
| `Go x -> string_of_int x
| `Star -> "*"
| `Box -> ""
@aklehm
aklehm / measure_util.dart
Created October 24, 2023 07:21
Util to measure the size of a flutter widget before build.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
/// Small utility to measure a widget before actually putting it on screen.
///
/// This can be helpful e.g. for positioning context menus based on the size they will take up.
///
/// NOTE: Use sparingly, since this takes a complete layout and sizing pass for the subtree you
/// want to measure.
///
Two pointers: one input, opposite ends
```python3
def fn(arr):
left = ans = 0
right = len(arr) - 1
while left < right:
# do some logic here with left and right
if CONDITION:
@hirrolot
hirrolot / CoC.ml
Last active May 15, 2025 13:25
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@Roaa94
Roaa94 / infinite_scrolling.dart
Last active September 25, 2023 15:47
Infinite Scrolling with Riverpod
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:dio/dio.dart';
// Disclaimer: This uses the "The Movie Database API (TMDB)"
// https://developers.themoviedb.org/3/getting-started
// With this endpoint:
// https://developers.themoviedb.org/3/people/get-popular-people
/// The FutureProvider that does the fetching of the paginated list of people
@alexanderameye
alexanderameye / SceneSwitcherToolbarOverlay.cs
Last active April 28, 2025 09:12
A small scene switcher utility for Unity
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.Overlays;
using UnityEditor.SceneManagement;
using UnityEditor.Toolbars;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
@PathogenDavid
PathogenDavid / NullRefChallenge.cs
Last active February 23, 2025 16:41
Crimes against the .NET Runtime -- Solution to this challenge on the C# Discord: https://discord.com/channels/143867839282020352/578057213084434433/943250054884515840
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
C local = null;
if (local != null && local.Prop)
{
Console.WriteLine(local.ToString()); // Null ref on this line
}
import 'package:flutter/material.dart';
class TabBarDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
@ecker00
ecker00 / SunPosition.cs
Last active December 15, 2021 13:10
Realistic sun position based on time of year and latitude/longitude in Unity 3D. Making it possible to simulate phenomena like the midnight sun. If this came in handy, say hi over at @SnutiHQ on Twitter.
// This code is licensed under the terms of the MIT license
using UnityEngine;
public class SunPosition : MonoBehaviour
{
[SerializeField, Range(-90f, 90f)]
public float latitude = 69.6546f;
[SerializeField, Range(-180f, 180f)]
public float longitude = 18.9637f;
@pdarragh
pdarragh / papers.md
Last active February 23, 2025 02:04
Approachable PL Papers for Undergrads

Approachable PL Papers for Undergrads

On September 28, 2021, I asked on Twitter:

PL Twitter:

you get to recommend one published PL paper for an undergrad to read with oversight by someone experienced. the paper should be interesting, approachable, and (mostly) self-contained.

what paper do you recommend?