Skip to content

Instantly share code, notes, and snippets.

View hollance's full-sized avatar

Matthijs Hollemans hollance

View GitHub Profile
@hollance
hollance / StateVariableFilter.h
Created August 26, 2023 16:26
Cytomic SVF implementation in C++
#pragma once
#include <cmath>
/**
State variable filter (SVF), designed by Andrew Simper of Cytomic.
http://cytomic.com/files/dsp/SvfLinearTrapOptimised2.pdf
The frequency response of this filter is the same as of BZT filters.
@hollance
hollance / CRUEL CANNON.PRG
Created March 5, 2024 20:29
Cruel Cannon, a hangman type game for the C64 written in BASIC, circa 1993
0 poke808,225:gosub 31000
1 poke53269,0
10 remifa=0thena=1:load"c.font3",8,1
20 remifa=1thena=2:load"lespirites",8,1
900 ww=68:dim n(ww):dim keer$(50)
1000 rem *** the game ***
1010 rem ** after a game over **
1015 poke 53265,peek(53265) and 239
1020 sc=0:gd=0:ft=0:ln=0:l$="":w$="":keer=1:keer$(0)="":keer$(1)=""
1030 gosub 20000:gosub 10000:jaja=0
@hollance
hollance / convert_weights.py
Created October 7, 2017 20:43
SE-ResNet-50 in Keras
# Convert SE-ResNet-50 from Caffe to Keras
# Using the model from https://github.com/shicai/SENet-Caffe
import os
import numpy as np
# The caffe module needs to be on the Python path; we'll add it here explicitly.
import sys
caffe_root = "/path/to/caffe"
sys.path.insert(0, caffe_root + "python")
@hollance
hollance / alignment-heads.md
Last active December 5, 2023 13:25
Alignment heads for Whisper word-level timestamps with Hugging Face Transformers

To allow the Hugging Face version of Whisper to predict word-level timestamps, a new property alignment_heads must be added to the GenerationConfig object. This is a list of [layer, head] pairs that select the cross-attention heads that are highly correlated to word-level timing.

If your Whisper checkpoint does not have the alignment_heads property yet, it can be added in two possible ways.

Method 1. Change the model.generation_config property:

# load the model
model = WhisperForConditionalGeneration.from_pretrained("your_checkpoint")
@hollance
hollance / NSObject+MHOverride.h
Created July 18, 2012 21:01
Overriding methods without making a subclass
@interface NSObject (MHOverride)
/*
* Dynamically overrides the specified method on this particular instance.
*
* The block's parameters and return type must match those of the method you
* are overriding. However, the first parameter is always "id _self", which
* points to the object itself.
*
@hollance
hollance / CoreML+Combine.swift
Created November 12, 2019 16:28
Using Core ML with Combine
import CoreML
import Combine
extension Publisher where Self.Output: MLFeatureProvider {
/**
Operator that lets you run a Core ML model as part of a Combine chain.
It accepts an MLFeatureProvider object as input, and, if all goes well,
returns another MLFeatureProvider with the model outputs.
@hollance
hollance / ZeroGravity.asm
Created November 23, 2016 19:50
Zero Gravity source code (Amiga 1200)
; *****************************************************************************
;
; $VER: ZeroGravity Source 1.0 (C) 1997 Matthijs Hollemans
;
; *****************************************************************************
;
; This is the full source code to Zero Gravity. I used the very cool ASM-One
; V1.29 assembler from T.F.A. but that doesn't matter anyway because you won't
; be able to reassemble this without the required binary includes...
;
@hollance
hollance / neural.c
Last active April 21, 2023 17:13
Playing with BNNS on macOS 10.12. The "hello world" of neural networks.
/*
The "hello world" of neural networks: a simple 3-layer feed-forward
network that implements an XOR logic gate.
The first layer is the input layer. It has two neurons a and b, which
are the two inputs to the XOR gate.
The middle layer is the hidden layer. This has two neurons h1, h2 that
will learn what it means to be an XOR gate.
@hollance
hollance / Barfdown.markdown
Last active March 25, 2023 18:16
A markdown-ish parser written in Swift 2.0

Barfdown: a Markdown-ish Parser Written in Swift

Goals for this project:

  • Parse a simplified version of Markdown that is good enough for writing my blog posts.
  • Be reasonably efficient. This means the parser shouldn't copy substrings around if not necessary. This is done by storing all the elements as indexes into the original text.
  • Be small and therefore be easy to understand.
  • No regular expressions. They are the lazy person's solution to parsing. ;-)

This is just a toy project for me to experiment with writing parsers in Swift. Because why not?

@hollance
hollance / eliza.swift
Last active February 17, 2023 15:50
The classic ELIZA chat bot in Swift.
/*
Joseph Weizenbaum's classic ELIZA chat bot in Swift.
Based on the IBM PC BASIC program from CREATIVE COMPUTING by Patricia
Danielson and Paul Hashfield, and the Java adaptation by Jesper Juul.
Run this script from Terminal:
$ swift eliza.swift
Press Ctrl-C or Ctrl-D to quit. (Or type "shut up".)