Skip to content

Instantly share code, notes, and snippets.

View hollance's full-sized avatar

Matthijs Hollemans hollance

View GitHub Profile
@hollance
hollance / deconv.py
Created May 13, 2017 20:47
Playing with "deconvolution"
import numpy as np
i = np.array(list(range(1, 50)), dtype=np.float).reshape((7, 7))
k = np.array(list(range(1, 10)), dtype=np.float).reshape((3, 3))
print("Input:"); print(i)
print("Kernel:"); print(k)
# Forward convolution. We need to pad the input so that we can read from
# its borders. (Not doing stride etc here.)
@hollance
hollance / XOR.swift
Created January 11, 2017 18:05
Playing with BNNS (Swift version). 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 / recursive-descent.swift
Created December 28, 2016 19:00
Simple recursive descent parser
import Cocoa
let input = "15,7, 3 ,, [1,2,[3, 4, 5], 6],8"
//let input = "5,7,[1]"
var index = input.characters.startIndex
var lookahead = input[index]
var done = false
func eat() {
@hollance
hollance / eliza.swift
Last active August 12, 2024 15:26
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".)
@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 / Evil Insects.txt
Created November 23, 2016 19:41
Really old source code
; ** START OF BLITZ 2 SOURCE **
; EVIL INSECTS
; ============
; Last changed: 30-06-94 (still 45 days and then...I'm 18)
; Author: Matthijs Hollemans
; This is the CHEATMODE, type it in correctly and you will be
; given 9 lives!
;
@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 / fmincg.swift
Created March 31, 2016 18:46
fmingc: minimizes a continuous differentiable multivariate function. Needs my Matrix type.
import Foundation
/**
Minimizes a continuous differentiable multivariate function.
Usage:
let (X, fX, i) = fmincg(f, X, length)
The starting point is given by `X` (a row vector).
@hollance
hollance / BoundedPriorityQueue.swift
Created March 19, 2016 17:56
BoundedPriorityQueue
public class LinkedListNode<T: Comparable> {
var value: T
var next: LinkedListNode?
var previous: LinkedListNode?
public init(value: T) {
self.value = value
}
}
@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?