Skip to content

Instantly share code, notes, and snippets.

@cokernel
cokernel / alpha.pl
Last active September 30, 2022 15:13
Sort numerals 1-99 alphabetically by English name.
#!/usr/bin/env perl
@l=(z,one,two,thir,four,five,six,seven,eigh,nine,ten,eleven,twelve);for(sort{e($a)cmp e($b)}1..99){print"$_\n"}sub e{$_=$_[0];($j,$d)=/./gs;$_<13?$_=$l[$_]:$j<2?$_=($l[$d].'teen'):($_=$l[$j].'ty'.($d?'-'.e($d):''))=~s/u//;s/h$/ht/;s/vet/ft/;s/ot/ent/;s/ir$/ree/;$_}
@cokernel
cokernel / example.txt
Created April 25, 2018 19:29
stato.pl - print basic stats and histogram of single column data set
$ ./stato.pl < log-counts.txt
n = 90
min = 120293
max = 239341
mean = 163764.722222222
sd = 22877.6153035703
72254 :
118009 : ***
127160 : *******
@cokernel
cokernel / keybase.md
Created January 9, 2018 14:54
keybase.md

Keybase proof

I hereby claim:

  • I am cokernel on github.
  • I am cokernel (https://keybase.io/cokernel) on keybase.
  • I have a public key ASAUTridD7arcOV7WFsZPgyu_HNjislk6EkbuCUMuFW4Pwo

To claim this, I am signing this object:

@cokernel
cokernel / turing.rb
Last active April 14, 2017 17:03
Turing machine simulator
#!/usr/bin/env ruby
# turing.rb - simulate a Turing machine
require 'json'
def print_state_radius(tm, step, radius)
description = sprintf("%010d:%s", step, tm['state'])
pos = tm['pos']
print "#{description} ..."
@cokernel
cokernel / charpoly-all.c
Last active August 30, 2016 17:42
Compute characteristic polynomial for graph Laplacian using Faddeev--LeVerrier
#include <stdio.h>
#include <string.h>
#define DEBUG 0
#define MAX_G6_LENGTH 256
long invert_r(int skip, int len, char *bits)
{
long output = 0;
for (int i = 0; i < len; ++i) {
@cokernel
cokernel / fetch_solr_ids.rb
Created March 19, 2015 12:39
Fetch all identifiers from a Solr index
#!/usr/bin/env ruby
# fetch_solr_ids.rb -- Fetch all identifiers from a Solr index
# This program is dedicated to the public domain.
require 'rubygems'
require 'rsolr'
# Configuration
rows_per_page = 100
filename = 'solr_ids.txt'
@cokernel
cokernel / sample_pdf.rb
Created November 14, 2014 16:35
Generate a sample PDF, testing hyphenation
require 'prawn'
require 'text-hyphen'
hh = Text::Hyphen.new
shy = Prawn::Text::SHY
source = 'Blacklight is an open source Solr user interface discovery platform. You can use Blacklight noninterruptable to longwordicationize searching and browsing of your collections. Blacklight uses the Apache Solr search engine to search full text and/or metadata. Blacklight has a highly configurable Ruby on Rails front-end. Blacklight was originally developed at the University of Virginia Library and is made public under an Apache 2.0 license.'
words = source.split(/\s+/)
hyphenated = words.collect {|w| hh.visualize(w, shy)}.join(' ')
@cokernel
cokernel / pdf_date
Created November 14, 2014 14:00
extract creation date from PDF
#!/bin/sh -e
# pdf_date: extract creation date from a PDF
#
# InfoKey: CreationDate
# InfoValue: D:20120207110303-05'00'
FILE=$1
DATE=$(pdftk "$FILE" dump_data_utf8 | perl -e '
@cokernel
cokernel / gist:ec51810b962d0d81436a
Created October 30, 2014 16:48
Generating test application for Blacklight 5.7.1
testing:$ ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
testing:$ rbenv --version
rbenv 0.4.0-98-g13a474c
testing:$ gem --version
2.2.2
testing:$ java -version
@cokernel
cokernel / castle-doctrine-osx-clang.diff
Created February 21, 2014 00:39
The Castle Doctrine - changes to compile on OSX 10.9 with clang and homebrew SDL
diff -Naur CastleDoctrine_v33_UnixSource/minorGems/game/platforms/SDL/Makefile.MacOSX CastleDoctrine_v33_UnixSource-clang/minorGems/game/platforms/SDL/Makefile.MacOSX
--- CastleDoctrine_v33_UnixSource/minorGems/game/platforms/SDL/Makefile.MacOSX 2014-02-20 15:34:25.000000000 -0500
+++ CastleDoctrine_v33_UnixSource-clang/minorGems/game/platforms/SDL/Makefile.MacOSX 2014-02-20 19:21:46.000000000 -0500
@@ -20,7 +20,7 @@
# various frameworks to support OpenGL and SDL
# static linking against zlib and libpng
-PLATFORM_LINK_FLAGS = -framework OpenGL -framework SDL -framework Cocoa ../../minorGems/game/platforms/SDL/mac/SDLMain.m ${CUSTOM_MACOSX_LINK_FLAGS}
+PLATFORM_LINK_FLAGS = -L/usr/local/bin -lSDLmain -lSDL -Wl,-framework,Cocoa -framework OpenGL -framework Cocoa ../../minorGems/game/platforms/SDL/mac/SDLMain.m ${CUSTOM_MACOSX_LINK_FLAGS}