Skip to content

Instantly share code, notes, and snippets.

View kjwierenga's full-sized avatar

Klaas Jan Wierenga kjwierenga

View GitHub Profile
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
@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
@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 <[email protected]> #
# Inspired by: MySQLARd (http://gert.sos.be/demo/mysqlar/) #
# Version: 1.5-r5 Released: 2009-11-22 #
# Licenced under GPLv2 #
# #
@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 / 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