Skip to content

Instantly share code, notes, and snippets.

View ariejan's full-sized avatar

Ariejan de Vroom ariejan

View GitHub Profile
@ariejan
ariejan / states.rb
Created May 13, 2013 08:37
States.
state_machine :state, initial: :concept do
state :concept
state :incomplete
state :complete
state :dismissed
event :cancel do
transition [:concept, :incomplete, :complete] => :dismissed
end
end
@Override
public void render(float delta) {
// Clear screen
Gdx.gl20.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl20.glClearColor(0f, 0f, 0.2f, 1f);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
// Set camera position
camera.position.set(new Vector3(player.getPosition().x, player.getPosition().y, 0));
camera.update();
let(:post) { create :post, body: "Blah en *narf*" }
it "let's Kramdown do the heavy lifting" do
kramdown = double
kramdown.should_receive(:to_html)
Kramdown::Document.should_receive(:new).with(post.body).and_return(kramdown)
helper.markdown(post.body)
end
AUTOMAKE_OPTIONS = foreign
SUBDIRS = src
@ariejan
ariejan / Dog.java
Created March 1, 2013 14:03
Simple jUnit example for @avdgaag's TDD presentation.
public class Dog {
public String bark() {
return "WOOF!";
}
}
@ariejan
ariejan / init-sidekiq.sh
Last active December 14, 2015 01:09
Init.d script for managing a Sidekiq worker.
#! /bin/bash
# /etc/init.d/gitlab
# GITLAB
# Maintainer: @randx
# App Version: 3.0
### BEGIN INIT INFO
# Provides: gitlab

Consider the following query

SELECT "orders".* FROM "orders" 
WHERE "orders"."bid" = 't' 
AND "orders"."region_id" = 10000002 
AND "orders"."type_id" = 30259 
ORDER BY price DESC
LIMIT 1

From a table with about 2.5million rows, it returns this one result in about 1075ms.

public abstract class BlockType {
public static byte VOID = 0;
public static byte DIRT = 1;
}
@ariejan
ariejan / work.sh
Created December 20, 2012 16:47 — forked from anonymous/gist:4346624
export COL=$COLUMNS ; grep '\[CatalogItem\] Retrieved' production.log | awk '{ print $6 $7 }' | ruby -ne 'BEGIN { puts ENV.inspect;$columns = ENV["COL"].to_i; $all = Hash.new { |h,k| h[k] = 0 } }; a, b = $_.split("(").map(&:to_f); next if a < 1; $all[((b/a/100).floor)] += a.to_i; END { max_value = $all.values.max; puts "\e[2J\e[f"; puts "Average request time".center($columns); print "\033[37m" ; puts "ms/req ±50ms".center($columns); print "\033[0m" ; puts ("─" * $columns); $all.keys.sort.each { |k| puts "#{(k * 100 + 50).to_s.rjust(6)}: \033[31m#{"▓" * ($all[k].to_f / max_value * ($columns - 8))}\033[0m"; }; puts "─" * $columns; print "\033[5m\033[35m" ; puts "(╯°□°)╯︵ ┻━┻ © Arjan & Ariejan".center($columns); print "\033[0m" }'
class Reader
has_many :memberships
has_many :magazines, through: :memberships
end
class Membership
belongs_to :reader
belongs_to :magazine
end