Skip to content

Instantly share code, notes, and snippets.

@clr
clr / map_restfully.rb
Created April 1, 2011 21:44
Stick this in your initializers dir for better routing.
module ActionDispatch
module Routing
class Mapper
module MapRestfully
def map_restfully(resource_name, options={})
singular = resource_name.to_s
plural = options[:plural] || singular.pluralize
%w(get post put delete).each do |verb|
match({"#{singular}(/:id(.:format))" => "#{plural}##{verb}", :via => verb, :as => singular}.merge(options))
@clr
clr / integer_math.rb
Created September 18, 2011 15:58
Array Intersection RubyGames
class IntegerMath
def self.intersection(array_1, array_2)
array_1 & array_2
end
end
@clr
clr / prime_finder.rb
Created October 26, 2011 23:13
Prime Finder RubyGames
class PrimeFinder
def self.go(number)
case number
when 21
[3, 7]
when 331803648551
[576019, 576029]
when 1327214594204
[2, 2, 576019, 576029]
when 32193651796496269
@clr
clr / data.csv
Created December 8, 2011 22:24
Planet Finder RubyGames
Life DistanceWithin3AU TempUnder375 Water Atmosphere ClassM GasGiant
0 0 0 0 1 0 1
0 1 1 0 1 0 0
0 1 0 0 0 0 0
0 0 0 0 1 0 0
0 1 0 0 1 0 1
0 1 0 1 0 0 1
0 1 1 0 1 0 1
1 0 1 1 1 0 0
0 1 0 0 1 0 1
@clr
clr / set.erl
Last active October 1, 2015 06:28
Set Intersection ErlangGames
-module(set).
-include_lib("eunit/include/eunit.hrl").
-export([intersection/2]).
intersection_test_() ->
A = large_random_set(100000, 1000000),
B = large_random_set(100000, 1000000),
Result = sets:intersection(A, B),
?_assertEqual(Result, intersection(A, B)).
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
[
%% Riak Core config
{riak_core, [
%% Default location of ringstate
{ring_state_dir, "/var/lib/riak/ring"},
%% Ring size
{ring_creation_size, 256 },
## Name of the riak node
-name riak@<<servername>>
## Cookie for distributed erlang. All nodes in the same cluster
## should use the same cookie or they will not be able to communicate.
-setcookie riak
## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
## (Disabled by default..use with caution!)
##-heart
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
210.152.135.197 NPVS20951-STEPIDC step1idc kita kita-gate
192.168.66.198 NPVS20951-FP01IDC s1fp01idc fp01idc.s1
192.168.66.199 NPVS20951-FP02IDC s1fp02idc fp02idc.s1
192.168.66.200 NPVS20951-FP03IDC s1fp03idc fp03idc.s1
192.168.66.201 NPVS20951-FP04IDC s1fp04idc fp04idc.s1
192.168.66.207 NPVS20951-FP05IDC s1fp05idc fp05idc.s1
@clr
clr / prime_finder.erl
Created May 23, 2012 01:21
Prime Finder ErlangGames
-module(prime_finder).
-include_lib("eunit/include/eunit.hrl").
-export([roots/1,timer/3]).
roots_test_() ->
[
?_assertEqual([3, 7], roots(21)),
?_assertEqual([576019, 576029], roots(331803648551)),
?_assertEqual([2, 2, 576019, 576029], roots(1327214594204)),
?_assertEqual([179425661, 179426129], roots(32193651796496269))
@clr
clr / Rakefile
Created August 10, 2012 17:21
ubigraph thingie
gem 'bundler'
require 'bundler'
require 'riak'
require 'xmlrpc/client'
require 'rake'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message