This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SETUP. | |
# | |
require 'picky' | |
# Users have a name and a list of blocked_ids. | |
# | |
User = Struct.new(:id, :name, :blocked_ids) do | |
# Generates a list of users which have not blocked this user. | |
# Note: Also excludes self. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Usage: | |
# p [pattern ...] | |
# | |
# Example: | |
# p E*.mp3 pop/A*.mp3 | |
# | |
files = Dir[ARGV.shift || '*.mp3', *ARGV].shuffle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run using | |
# ruby facets.rb | |
# | |
require 'picky' | |
# Define index. | |
# | |
data = Picky::Index.new :models do | |
category :id | |
category :name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}." |