Skip to content

Instantly share code, notes, and snippets.

View kjwierenga's full-sized avatar

Klaas Jan Wierenga kjwierenga

View GitHub Profile
@kjwierenga
kjwierenga / machine.js
Last active April 24, 2021 19:10
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@kjwierenga
kjwierenga / gist:3866358
Created October 10, 2012 15:30
Character frequency of text in Ruby
#!/usr/bin/env ruby
text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
freqs = text.downcase.tr(".\n ",'').chars.inject(Hash.new(0)) { |freq,c|
freq[c] += 1; freq }.to_a.sort{ |a,b| a.last <=> b.last}
@kjwierenga
kjwierenga / tuning-primer.sh
Created June 27, 2011 10:16
MySQL performance tuning primer script version 1.5-r5
#!/bin/sh
#########################################################################
# #
# MySQL performance tuning primer script #
# Writen by: Matthew Montgomery <mmontgomery@mysql.com> #
# Inspired by: MySQLARd (http://gert.sos.be/demo/mysqlar/) #
# Version: 1.5-r5 Released: 2009-11-22 #
# Licenced under GPLv2 #
# #
@kjwierenga
kjwierenga / dijkstra.rb
Created June 1, 2011 07:55
Dijkstra's Algorithm in Ruby
# From http://www.algolist.com/code/java/Dijkstra%27s_algorithm
# Here you can find the algorithm in Java, C, C++, Python, Ruby and PHP.
#
# You need pqueue: gem install pqueue
#
require 'pqueue'
class Algorithm
INFINITY = 1 << 32
class Configuration
class AppServer
attr_accessor :port, :admin_password
end
def initialize
@app_server = AppServer.new
end
attr_accessor :tail_logs, :max_connections, :admin_password, :app_server
# My final solution to 'Closures' exercise at the
# Scottish Ruby Conference - Ruby Tutorial
# by Chad Fowler and Keavy McMinn.
# The returning keyword/proc is not defined in Ruby 1.8. Define it here
#
def returning(value, &block)
yield
value
end
def returning(value, &block)
yield
value
end
def counter(start, inc)
lambda do
returning start do
start += inc
end
def counter(start, inc)
lambda do
current = start
start += inc
current
end
end
result = counter(10, 2)
Getting up and running with OS X, Textmate & Scheme
===================================================
SCHEME
======
I ran across two implementations of Scheme which appear to work well with OS X.
mit-scheme & PLT Scheme.
I was able to install mit-scheme from darwin ports ( sudo port install mit-scheme)
@kjwierenga
kjwierenga / yesterdate-linux.sh
Created September 7, 2010 07:12
Determine yesterday's date (yesterdate) in ruby or shell (linux and OSX)
> date -d-1day
Mon Sep 6 09:08:43 CEST 2010
> date -d-1day +%Y%m
201009