Skip to content

Instantly share code, notes, and snippets.

View tristang's full-sized avatar

UsabilityHub tristang

  • UsabilityHub
  • Melbourne, Australia
View GitHub Profile
@tristang
tristang / open_struct_struct_hash.rb
Created September 2, 2016 13:50
OpenStruct vs Struct vs Hash performance
require 'benchmark'
require 'ostruct'
REP = 1000000
User = Struct.new(:name, :age)
USER = "User".freeze
AGE = 21
HASH = {:name => USER, :age => AGE}.freeze
@tristang
tristang / gist:814e7fdedafa429297d5
Last active August 29, 2015 14:18
Tests passing for issue 19042 with patch tristang/rails:require-option-for-counter-cache
==================
== UN PATCHED ====
==================
-- create_table(:posts, {:force=>true})
D, [2015-04-07T21:48:33.198419 #6407] DEBUG -- : (0.3ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "comments_count" integer DEFAULT 0)
-> 0.0067s
-- create_table(:comments, {:force=>true})
D, [2015-04-07T21:48:33.198977 #6407] DEBUG -- : (0.1ms) CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "post_id" integer)
-> 0.0005s
@tristang
tristang / counter_cache_tests
Created March 31, 2014 01:05
Tests for counter_cache when option is not given
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts do |t|
t.integer :comments_count, default: 0
@tristang
tristang / crimea.csv
Created March 29, 2012 01:46 — forked from mbostock/.block
Stacked Bar Chart
date wounds other disease
5/1854 0 95 105
6/1854 0 40 95
7/1854 0 140 520
8/1854 20 150 800
9/1854 220 230 740
10/1854 305 310 600
11/1854 480 290 820
12/1854 295 310 1100
1/1855 230 460 1440
@tristang
tristang / importance-dummy.json
Created March 28, 2012 01:32
Reorderable stacked bar
{
"rows" : [
{
"attribute" : "Some attribute",
"id" : "id_0",
"very_important" : 0.2,
"important" : 0.2,
"not_very_important" : 0.2,
"not_at_all_important" : 0.2,
"do_not_know" : 0.2