Skip to content

Instantly share code, notes, and snippets.

@camertron
camertron / clone_all_cskit.sh
Created December 14, 2013 04:21
Clone all cskit repos
#! /bin/bash
git clone [email protected]:CSOBerkeley/cskit-rb.git
git clone [email protected]:CSOBerkeley/cskit-shkts-rb.git
git clone [email protected]:CSOBerkeley/cskit-biblekjv-rb.git
git clone [email protected]:CSOBerkeley/cskit-hymnal-rb.git
@camertron
camertron / rbnf_example.rb
Last active December 23, 2015 18:19
Rule-based Number Formatting with twitter-cldr-rb
# clone twitter-cldr-rb, change to rbnf branch
# Note: There are probably bugs with this implementation, and the function names will
# likely change (underscores instead of camel case, for example). Use only with the
# understanding that you will probably have to change your code later.
#
# Any and all questions/comments always appreciated!
require 'twitter_cldr/formatters/numbers/rbnf/en'
puts TwitterCldr::Formatters::RuleBasedNumberFormatter::English.renderDigitsOrdinal(123)
@camertron
camertron / tiles.rb
Last active December 22, 2015 00:58
Dashboard tiles
class DashboardTile
PARAMS = [
:image, :name, :description, :count,
:count_suffix, :status, :url, :url_class
]
PARAMS.each do |param|
define_method(param) { raise NotImplementedError }
define_method(:"#{param}=") { raise NotImplementedError }
end
@camertron
camertron / immutable_strings.rb
Last active December 21, 2015 19:49
Making Ruby Strings Immutable by Default
module BeforeMethodHook
def before(*names)
names.each do |name|
m = instance_method(name)
define_method(name) do |*args, &block|
yield self
m.bind(self).call(*args, &block)
end
end
end
@camertron
camertron / index.html
Last active December 20, 2015 15:19
CSKit Annotations from Strong's Concordance
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CSKit HTML Example</title>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<style>
.cskit-strongs-word {
@camertron
camertron / activerecord_outer_join.rb
Last active December 14, 2015 16:49
Outer Join on an Association in ActiveRecord
class Project < ActiveRecord::Base
has_and_belongs_to_many :phrases
end
class Phrase < ActiveRecord::Base
has_and_belongs_to_many :projects
end
join_dependency = ActiveRecord::Associations::JoinDependency.new(Project, [:phrases], [])
@camertron
camertron / mountain-grade.txt
Created February 25, 2013 04:19
Slope of Mountain
/
/ |
/ |
116,435 / |
/ | 8,000
/ x |
___________
116,160
soh cah toa
@camertron
camertron / count_ones.rb
Last active October 13, 2015 18:17
Count 1 bits in integer (Ruby)
# protip: use Ruby 1.9 for block support with Enumerable#count
def count_ones(num)
return 0 if num == 0
digits = Math.log2(num).floor + 1
0.upto(digits).count do |i|
num & (2 ** i) == (2 ** i)
end
end
@camertron
camertron / decompositon_map.rb
Created July 28, 2012 23:17
Dumping the decomposition map to yml
require 'twitter_cldr'
require 'fileutils'
require 'yaml'
OUTPUT_FILE = "/tmp/cldr/decomposition_map.yml"
CODE_POINT_MAX = 1114111
decomps = {}
CODE_POINT_MAX.times do |i|
code_point = TwitterCldr::Shared::CodePoint.for_hex(i.to_s(16))
@camertron
camertron / composition_exclusions.rb
Created July 28, 2012 22:29
Dumping composition exclusions into yml
require 'open-uri'
require 'fileutils'
require 'yaml'
PROPS_URL = "http://www.unicode.org/Public/6.1.0/ucd/DerivedNormalizationProps.txt"
OUTPUT_FILE = "/tmp/cldr/composition_exclusions.yml"
EXPECTED_TOTAL_POINTS = 1120
data = open(PROPS_URL).read
start_pos = data.index("# Derived Property: Full_Composition_Exclusion")