Skip to content

Instantly share code, notes, and snippets.

View jameshfisher's full-sized avatar
🏠
Working from home

Jim Fisher jameshfisher

🏠
Working from home
View GitHub Profile
@jameshfisher
jameshfisher / trie.go
Created May 15, 2010 19:05
A trie structure, storing []byte elements, implemented in Go
package trie
import (
"container/vector"
"sort"
)
// A 'set' structure, that can hold []byte objects.
// For any one []byte instance, it is either in the set or not.
type Trie struct {
@jameshfisher
jameshfisher / pearson.go
Created May 18, 2010 22:31
A Go implementation of Pearson hashing
package pearson
/* Get an initial hash value by passing in the length of the array. */
func Init(length int) (hash byte) { return byte(length % 256) }
/* Given the hash of a string S0..SN and the character SN+1,
get the hash of the string S0..SN+1.
*/
func FeedByte(oldhash byte, next byte) (newhash byte) {
/* The following table is the result of the pseudorandom order at
@jameshfisher
jameshfisher / rust_0.2_compile_segfault.bash
Created July 2, 2012 23:06
Segfault compiling Rust 0.2
james@bast:~$ cd /tmp/
james@bast:/tmp$ tar -xvf rust-0.2.tar.gz
rust-0.2/
rust-0.2/Makefile.in
rust-0.2/mk/
rust-0.2/mk/snap.mk
rust-0.2/mk/llvm.mk
rust-0.2/mk/docs.mk
rust-0.2/mk/platform.mk
rust-0.2/mk/install.mk
@jameshfisher
jameshfisher / NinetyNine.hs
Last active December 11, 2015 01:48
initial
module NinetyNine where
import Data.List (foldl')
-- Problem 1: Find the last element of a list.
myLast :: [a] -> a
myLast [] = error "myLast []"
myLast (x:xs) = foldl' (flip const) x xs
-- Problem 2: Find the last but one element of a list.
@jameshfisher
jameshfisher / PHP_semantics.md
Last active April 18, 2023 14:53
Semantics for PHP

PHP semantics

Motivation

PHP is usually included in the top five or six most popular programming languages, as measured by various metrics implemented by e.g. [Tiobe][], [LangPop][], [PYPL][], [lang-index][]. Alongside it sit C, Java, Obj-C, C++, C#, Javascript, and Python. All of these have a formal semantics or at least a rigorous specification.

@jameshfisher
jameshfisher / halting_problem_javascript.md
Last active September 7, 2017 01:04
A proof that the Halting problem is undecidable, using JavaScript and examples

Having read a few proofs that the halting problem is undecidable, I found that they were quite inaccessible, or that they glossed over important details. To counter this, I've attempted to re-hash the proof using a familiar language, JavaScript, with numerous examples along the way.

This famous proof tells us that there is no general method to determine whether a program will finish running. To illustrate this, we can consider programs as JavaScript function calls, and ask whether it is possible to write a JavaScript function which will tell us

@jameshfisher
jameshfisher / Javaland.md
Last active January 2, 2016 07:29
Javaland

An introduction to Javaland

Javaland is notorious for its acronyms, inconsistent and redundant naming, bundling of multiple things into new definitions, circular definitions, and so on.

This file aims to reduce this incomprehensible mess into a set of succinct definitions. This should read like a dictionary, where all definitions only refer to prior definitions.

The JVM

Java bytecode refers to two things:

@jameshfisher
jameshfisher / How to make a private Gist public.md
Created January 5, 2014 16:31
How to make a private Gist public

Github provides no facility to do this via the UI. This is sad, because it would be extremely useful in order to draft something before publishing it. It would also be trivial for them to implement. Never mind; here's how to do it manually:

  1. Get the "Clone this Gist" text from the left-hand side of the private Gist, e.g. https://gist.github.com/b9cc265982870c091a1e.git, and extract the ID b9cc265982870c091a1e.
  2. Go to https://gist.github.com/ and create a dummy new public Gist.
  3. Get the "Clone this Gist" text from the left-hand side, e.g. https://gist.github.com/8270253.git, and extract the ID 8270253.
  4. git clone git@gist.github.com:b9cc265982870c091a1e tmp-dir && cd tmp-dir && git push -f git@gist.github.com:8270253.git
@jameshfisher
jameshfisher / ORM_constraints.md
Last active January 4, 2016 12:59
ORM correctness constraints

ORM correctness constraints

At an old workplace, we used the Hibernate ORM to map a class hierarchy to our relational database. Hibernate represents a class hierarchy in the following way. Let's say we have the tables:

abstract class A
class B extends A
class C extends A
@jameshfisher
jameshfisher / restore-file-from-package.sh
Created April 12, 2014 17:44
Restore a file from the package that provides it.
#!/bin/bash
# Usage:
#
# sudo ./restore-file-from-package.sh <filepath>
#
# Restore a file from the package that provides it.
#
# Source: http://askubuntu.com/a/67028/30482