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 / perfer
Last active January 2, 2016 05:59
Comparison of 1000 queries each using Picky running on Ruby 1.9 and 2.1. (Not a good absolute measurement, as the case is pathological – but good for comparison between Rubies)
hanke@soyuz:performance:[master *] chruby 1.9
hanke@soyuz:performance:[master *] perfer run -m 5 perfer.rb
Sanity check:
>|2014-01-04 21:34:25|0.000096|florian | 1| 0| 1|
Session Search#search with ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.4.0]
Taking 5 measurements of at least 1.0s
Search#search('florian') with variable index size and fixed search size 1024 in 68.06 ms ± 6.077 ( 8.9%)
Search#search('florian') with variable index size and fixed search size 2048 in 82.98 ms ± 6.361 ( 7.7%)
@floere
floere / embedded_strings.rb
Last active December 21, 2015 13:49
String#split behaviour with embedded strings.
s = "One Two Three" # Shorter than 24 characters.
s.split /\s/ # Uncomment and comment. Why does the original string now occur 2 more times (1 per match?) in the ObjectSpace than without splitting?
times = 0
ObjectSpace.each_object(String) do |str|
times += 1 if str == s
end
p times
@floere
floere / prettyprint.sh
Created May 9, 2013 12:22
Printing with line numbers, color, and wrapping into a PDF.
~/bin $ cat prettyprint
#!/bin/sh
PDF_FILE=/tmp/temp.pdf
PS_FILE=/tmp/temp.ps
vim \
"+set number" "+syntax on" "+color slate" \
"+set printoptions=number:y" \
"+set printfont=courier:h9" \
@floere
floere / search_blocked_users.rb
Created April 23, 2013 21:16
An example of how to exclude blocked users from search results.
# 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.
@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)
#