Skip to content

Instantly share code, notes, and snippets.

View jozip's full-sized avatar
☺️
👍

Johan Persson jozip

☺️
👍
View GitHub Profile
@jozip
jozip / lexer.rb
Created February 19, 2011 23:18
A simple declarative lexer
# lexer.rb -- A simple declarative lexer
#
# Cobbled together by Johan Persson <johan.z.persson@gmail.com>
#
# Based on Martin Fowler's lexer wrapper in the article
# http://martinfowler.com/bliki/HelloRacc.html
#
# The following example defines a tiny lexer for Erlang lists
# and atoms:
#
@jozip
jozip / byte_buffer.rb
Created February 20, 2011 00:03
A simple byte buffer
# byte_buffer.rb -- A simple byte buffer
#
# A sad story by Johan Persson <johan.z.persson@gmail.com>
#
# This hack makes it easy to read, write, manipulate and interpret
# sequences of bytes. It's heavily modelled on the way Jinterface
# (of Erlang) codes and decodes data, so it might be a bit inelegant.
#
# The code should be kind of self-explanatory.
class Object
def define_eigenmethod(m, &b)
(class << self; self end).send(:define_method, m, &b)
end
end
def Binary(ps)
Class.new do
define_eigenmethod(:unit) do |unit = nil, &b|
require 'digest/sha2'
class Key < Binary 'H*'
unit :to_s
class << self
def hexdigest(src, bitlen = 256)
Digest::SHA2.new(bitlen).update(src.to_s).to_s
end
def gen(src)
@jozip
jozip / gist:970097
Created May 13, 2011 06:50 — forked from qerub/gist:969308
Objective-R: Objective-C-like syntax for method calls in Racket
#lang racket
; TODO: Add support for nested method calls
(require syntax/stx)
(provide read read-syntax)
;; Apply/Eval for this schemelet
(define (apply-objective-r form)
@jozip
jozip / SECD.hs
Created June 6, 2011 20:05
A family of SECD variants
-- Based on "A Rational Deconstruction of Landin's SECD Machine" by Olivier Danvy
-- (BRICS-RS-03-33)
module SECD where
import Data.Maybe
type Ident = String
type Env a = [(Ident, a)]
@jozip
jozip / gist:1916193
Created February 26, 2012 11:24
brew install emacs --cocoa
==> Downloading http://ftpmirror.gnu.org/emacs/emacs-23.3b.tar.bz2
File already downloaded in /Users/toki/Library/Caches/Homebrew
/usr/bin/tar xf /Users/toki/Library/Caches/Homebrew/emacs-23.3b.tar.bz2
==> Downloading patches
/usr/bin/curl -qf#LA Homebrew 0.8.1 (Ruby 1.8.7-249; Mac OS X 10.7.3) http://repo.or.cz/w/emacs.git/commitdiff_plain/c8bba48c5889c4773c62a10f7c3d4383881f11c1 -o 001-homebrew.diff https://raw.github.com/gist/1746342/702dfe9e2dd79fddd536aa90d561efdeec2ba716 -o 003-homebrew.diff --silent
==> Patching
/usr/bin/patch -f -p1 -i 001-homebrew.diff
patching file src/ChangeLog
patching file src/unexmacosx.c
/usr/bin/patch -f -p1 -i 002-homebrew.diff
@jozip
jozip / backup.sh
Last active August 29, 2015 14:10
#!/bin/bash
#
# Argument = -u user -p password -k key -s secret -b bucket
#
# To Do - Add logging of output.
# To Do - Abstract bucket region to options
set -e
export PATH="$PATH:/usr/local/bin"

Keybase proof

I hereby claim:

  • I am jozip on github.
  • I am jzp (https://keybase.io/jzp) on keybase.
  • I have a public key ASBCxRR85czZANle-HaZPsWYnam4nNQKLm7Ko2pHoLeiWAo

To claim this, I am signing this object:

@jozip
jozip / code39.js
Last active January 20, 2019 19:06
Unicode barcode generator in glorious javascript
// code39.js -- Unicode barcode generator
// Ported from from Trammell Hudson's original Perl script
// by Johan Persson <jzp@bahnhof.se>
//
// Original header:
// Generate code39 barcodes with unicode characters.
// This doesn't really have a purpose.
// https://trmm.net/Barcode
var patterns = {