Skip to content

Instantly share code, notes, and snippets.

View lcowell's full-sized avatar

Luke Cowell lcowell

View GitHub Profile

This is my modest attempt at a key value store. I use the filesystem to store any object or data requested to be set. `runner` will give you a demonstration of how it works. Right now, the folder splitting depth is 1 so a key like apple would be in /a/apple.

I included a `benchmark` as I’d be curious as to how this entry performs compared to others. Even then my benchmark is far from exhaustive. My keys in the test are random, a better test would see what impact grouping keys together would have. eg (aa, ab, ac). FsStore may also perform well with smaller numbers of keys, but when the number of keys gets to be over a certain size, I can see there being a significant performance hit as the OS tries to find one file in a directory of 10000. I also noticed on my system, which is a mac, that creating 10000 keys at once, makes mds get really busy, I should probably put the data store in a folder with .noindex appended so mds leaves it alone.

# Sessions are the anchor for most activity on the site. Almost every resource will be
#related to a session. Sessions have 3 states: open, closed and published.
session = IwiSession.find(params[:id])
# New Sessions
# A session is by default an open session. When making a new session, the participants from
# the previous session are copied forward. The most recent previous session will exclude one-time
# sessions.
@lcowell
lcowell / 1_basic_benchmark.rb
Created November 7, 2011 00:12
Benchmarking
n = 1_000_000
start_time = Time.now
for i in 1..n; a = "1"; end
end_time = Time.now
puts "total time for the operation was #{end_time - start_time} seconds"
start_time = Time.now
n.times do; a = "1"; end
@lcowell
lcowell / non_tap.rb
Created November 15, 2011 16:23
Tapity Tap
def configure_store
store = App::Store.build
store.config!
return if store.check_for_other_store_instances
end
@lcowell
lcowell / simple.rb
Created November 15, 2011 23:25
Method Missing
require 'benchmark'
class HighChild
def foo
end
def method_missing(method, *args, &block)
end
end
# we can name each result set eg. top_male_times_this_season
result
| name |
# it's unlikely that we're going to reuse results, so we should scope them by the result they belong to
results
| age | time | gender | result_id |
| 23 | 55:11 | M | 1 |
| 49 | 1:27:51 | F | 2 |
def configure(token)
user = User.find_by_token(token)
user.update_attributes(:confirmed => true) if user
user
end
# Say you have different types of pet classes. It appears that using method_missing is preferable
# over using DelegateClass as we can decide our target at runtime. Is there a way to accomplish
# this type of behaviour using DelegateClass ?
def PetDecorator
def initialize(target)
@target = target
end
def talk
class Deal < AR
attr_reader :minimum_order, :board_lot_size, :unit_value, :allocation_value
end
# last level allocation rate
# planned allocations
# deal
class DealAllocation < AR
belongs_to :deal
@lcowell
lcowell / gist:1728345
Created February 3, 2012 05:33
avoiding included {} with ActiveSupport::Concern

We can call a class macro on an instance of a class like this:

class Foo attr_accessor :bar end

Foo.new.bar = 1

We can call a class macro on the class in this way: