Skip to content

Instantly share code, notes, and snippets.

View floere's full-sized avatar
😁
Open Sourcing

Florian R. Hanke floere

😁
Open Sourcing
View GitHub Profile
@floere
floere / picky_basic_script.rb
Created November 9, 2012 11:02
Picky basic script example
require 'picky'
Person = Struct.new :id, :age, :name
data = Picky::Index.new :people do
category :age, partial: Picky::Partial::None.new
category :name
end
data.replace Person.new(1, 34, 'Florian')
@floere
floere / infix_search_example.rb
Created November 6, 2012 21:42
Infix search example (copy & paste)
require 'picky'
Person = Struct.new :id, :age, :name
data = Picky::Index.new :people do
category :age, partial: Picky::Partial::None.new
category :name, partial: Picky::Partial::Infix.new(min: 1, max: -1)
end
data.replace Person.new(1, 34, 'Florian')
@floere
floere / p
Created September 12, 2012 18:36
A better iTunes
#!/usr/bin/env ruby
#
# Usage:
# p [pattern ...]
#
# Example:
# p E*.mp3 pop/A*.mp3
#
files = Dir[ARGV.shift || '*.mp3', *ARGV].shuffle
@floere
floere / facets.rb
Created July 18, 2012 02:52
A 5 minute implementation of facets on Picky.
# Run using
# ruby facets.rb
#
require 'picky'
# Define index.
#
data = Picky::Index.new :models do
category :id
category :name
@floere
floere / object_pool.rb
Created July 16, 2012 08:41
Ruby Object Pool
# Module that handles object pool behaviour
# for you.
#
# Usage:
# class Thing
# extend Pool
#
# def initialize a, b, c
# @a, @b, @c = a, b, c
# end
@floere
floere / nosinatra.rb
Created July 9, 2012 08:32
Using Ricer and no Sinatra for a high speed Picky.
# Remove the Sinatra class from the Picky example app
# and replace the get call with this:
#
# Then, run e.g.
# ab -n 1000 -c 10 '127.0.0.1:3000/?query=a&ids=20&offset=0'
# (simple)
# or
# ab -n 1000 -c 10 '127.0.0.1:3000/?query=a*-a*-a&ids=20&offset=0'
# (complex)
#
@floere
floere / ab.txt
Created July 7, 2012 12:56
Picky book example speed without Sinatra and using ricer.
~/temp/picky/server/performance_tests (master) $ ab -n 1000 -c 10 'localhost:3000/books?query=test'
This is ApacheBench, Version 2.3 <$Revision: 1178079 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
@floere
floere / loader.rb
Created June 29, 2012 01:36
Live Reloading of Code: Presentation at Melbourne Roro
# Version 1: Fails, since this file is not reloaded.
#
module Loader
def self.reload
puts "Loading application."
load File.expand_path "../worker.rb", __FILE__ # Change this to new_worker
load File.expand_path "../signal.rb", __FILE__
end
# Encoding: UTF-8
#
require 'fiber'
# This accepts generated frames and prints them.
#
target = Fiber.new do
loop do
frame = Fiber.yield
puts "Frame received: #{frame}."
@floere
floere / ends.rb
Created March 27, 2012 19:59
The END block in Ruby.
END { p "This is the end, my only friend, the end." }
p "Feeling very sleepy..."
sleep 1