Skip to content

Instantly share code, notes, and snippets.

View 0cjs's full-sized avatar
🏠
Building an MC6800 simulator!

Curt J. Sampson 0cjs

🏠
Building an MC6800 simulator!
View GitHub Profile
@0cjs
0cjs / read_ascii_byte.a65
Created September 27, 2019 13:26
6502 code (not very good) to read the two-char ASCII representation of a byte and convert it to a binary byte
;---------------------------------------------------------------------
; Read (using bsread) a pair of ASCII chars representing a printable
; byte value, and convert it to that byte value, returning it in A.
asc_0 .equ 30
asc_9 .equ 39
asc_A .equ 41
asc_F .equ 46
.area ZP
@0cjs
0cjs / java-haskell-verbosity.md
Created May 30, 2019 02:21
Verbosity of Java vs. Haskell

Verbosity of Java vs. Haskell

This article gives a simple purely functional sorted, unbalanced tree structure in 67 lines of java. The direct Haskell translation below is 13 lines; Java's verbosity ratio is 5.15.

data (Ordered a) => SortedSet a = Empty | Node (SortedSet a) a (SortedSet a)
#!/usr/bin/env bash
set -o pipefail
. "$(git --exec-path)/git-sh-setup"
#
# Also see "$(git --exec-path)/git-filter-branch" for, e.g., a list of
# functions available in the commit filter.
# set_reflog_action
#!/usr/bin/env bash
#
# describe-pr - print a Pull Request description
#
type xsel >/dev/null 2>&1 || {
echo 1>&2 "$(basename $0): xsel command not found; please install it."
exit 1
}
# (This doesn't currently work on a Mac, where we'd use the `pbpaste`
@0cjs
0cjs / initialize_vars.rb
Last active September 4, 2022 16:40
Replace boilerplate Ruby `def initialize` followed by instance variable settings with `initialize_vars` specifying variables once
# XXX This worked in 2009 with Ruby 1.8; I've not tested on anything
# more recent. But you get the general idea.
class Class
def initialize_vars(*vars, &initialize_block)
vars.each { |arg| attr_reader arg.to_sym }
varsyms = vars.collect { |arg| ('@' + arg.to_s).to_sym }
define_method(:initialize) { |*init_args|
raise(ArgumentError, "wrong number of arguments " +
@0cjs
0cjs / git-test-log
Last active March 11, 2017 06:04 — forked from nishantjr/git-test-log
git-test-log
#!/usr/bin/env bash
# If no commits specified, we default to HEAD@{u}..HEAD. However if HEAD is uptodate,
# then `rev-parse` returns nothing. In that case we fallback to HEAD^..HEAD.
# XXX: This breaks if `some-other-brach@{u}..some-other-brach` is specified.
# adding a `--boundary` should have solved this issue, but there seems to be
# a bug in `git rev-parse` and `git rev-list`.
parsed_revs=($(git rev-parse --revs-only "$@" --default HEAD@{u}..HEAD))
[ ${#parsed_revs[@]} = 0 ] && parsed_revs=(HEAD ^HEAD^)
@0cjs
0cjs / gist:2c0f78c21649af8466e9b50c1e5f7df8
Created February 28, 2017 05:17
Find true base directory of current shell script, regardless of symlinks
set_basedir() { # This is portable; don't touch it!
local dir path0="$0"
while [ -h "$path0" ]; do
dir="$(cd "$(dirname "$path0")" && pwd -P)"
path0="$(readlink "$path0")";
[ "$(echo "$path0" | cut -b 1)" = / ] || path0="$dir/$path0"
done
basedir="$(cd "$(dirname "$path0")/.." && pwd -P)"
}; set_basedir
#!/bin/bash
#
# mdpreview - preview a markdown file
#
# Idea from:
# https://ubuntuincident.wordpress.com/2011/05/05/readme-markdown-on-github/
#
# This does not handle the Github variations documented at:
# https://help.github.com/articles/github-flavored-markdown
# You may want to try using a gist to get a more accurate preview.

Hello there! This is a sample post for gist.io, a super-lightweight writing soapbox for hackers.

Now look up. Further. Above the post title. See that grey text with the gist ID?

Now back to me. That grey text is a link! Open that sucker in a new tab to see the source for this post. Also, I'm on a horse.

This is a major heading

If you peek at it with a web inspector, you'll see that it is a second-level heading. You can use first level headings, but they'll look just like the second level ones, and the gods of the HTML5 outlining algorithm will frown upon you.