Skip to content

Instantly share code, notes, and snippets.

View rfielding's full-sized avatar

Robert Fielding rfielding

View GitHub Profile

This is a heapsort I did from memory a few days ago. The main thing about it is that the array starts out with 0 items in the heap, where everything is in the array, unsorted. Then, using no extra space, move each item into the heap, and ensure that the parent is never less than any child. By the time we have put everything into the heap, it is "heapified". It is a priority queue, where the item at the top, at index 0 is the greatest element.

We then swap out the greatest item to the next item in the list, from the right. Every time we remove an element, we make sure that the top item bubbles down, until

@rfielding
rfielding / gist:cbfdca49a6320685cb8e7cfc6bbb0449
Last active December 20, 2024 06:58
This Lean proof had some Claude assistance. S=(1+2+3+...+n)+Tail_S(n).

I thought this would be the very end of objections to the result. In Lean, the last theorem, was stated like this initially:

theorem Sgoal : Sum_S n + Tail_S n = -1/12

Where Sum_S is the finite part of terms expanded out, n*(n+1)/2, and Tail_S n is Sf n - Sum_S n, where Sf n is a constant value that I got by solving for Sf n starting from subtracting B from S

#!/bin/env python3
# Andrej Karpathy - Reinforcement learning demo, fixed to work in Python3.7
#
# http://karpathy.github.io/2016/05/31/rl/
#
# - Python3 fixes
# - I used conda
# - You have to install the atary_py separately, AND also import all the Atari ROMs separately
#
# Algebraic Calculus
# All rules with partials - on binary operators where BOTH args are not necessarily constant
d[f + C] : (d[C]==0) = d[f]
d[a + b] = d[a] + d[b]
d[a * b] = a * d[b] + d[a] * b
# a and b must commute for this definition
d[a^b] = b * a^(b-1) * d[a] + log_e[a] * a^b * d[b]
# a and b must commute for this definition
# Notice that log is a binary operator, where the base can vary, for completeness!
d[log_a[b] = (-1/a) ln[b]/(ln[a]^2) * d[a] + (1/b) * (1/ln[a]) * d[b]

Keybase proof

I hereby claim:

  • I am rfielding on github.
  • I am robfielding (https://keybase.io/robfielding) on keybase.
  • I have a public key ASCdxoKdgZzx54mus0dnAwN2L4OSqJBTMw5QXndke-6VYgo

To claim this, I am signing this object:

/*
Schematic:
Just stack an Arduino Uno (r3) with a Olimex MIDI shield.
Plug in MIDI in to a keyboard, and MIDI out to a synth.
Ensure that MIDI channel out is same as channel receiving in synth (this does not channel rewrite).
This proxy works by:
- was last note down lower than -6 semitones from last?
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Error;
//#[allow(dead_code)]
#[derive(Copy,Clone)]
enum Opb {
PAIR,
ADD,
SUB,
@rfielding
rfielding / An excerpt of how it's used
Created January 5, 2012 22:17
Fixing a huge omission in MIDI, note-ties
if(fingerTurningOff != NOBODY)
{
struct Fretless_fingerState* turningOffPtr = &ctxp->fingers[fingerTurningOff];
if(turningOffPtr->isOn == FALSE)
{
ctxp->fail("turningOffPtr->isOn should be on\n");
}
if(turningOffPtr->isSupressed == FALSE)
{
ctxp->fail("turningOffPtr->isSupressed should be supressed\n");
@rfielding
rfielding / Fretless.h
Created December 19, 2011 18:45
Hiding the vulgarities of MIDI behind a frequency oriented interface.
//
// Fretless.h
// AlephOne
//
// Created by Robert Fielding on 10/14/11.
//
// This should remain a *pure* C library with no references to external libraries
/*
* There is no internal global state, so this entire library is re-entrant.
//WHAT A LIE. Measure it by recording the diff between acoustic and instrument output
float latency = 0.005;
OSStatus status =
AudioSessionSetProperty(
kAudioSessionProperty_PreferredHardwareIOBufferDuration,sizeof(latency),
&latency
);