def wrap(string, before: "<", after: ">")
"#{before}#{string}#{after}" # no need to retrieve options from a hash
end
# optional
This file contains 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 | |
require "socket" | |
# This is a simple preloader for Ruby apps. | |
# Usage: | |
# Put this file somewhere in your PATH, named 'ruby_preloader' and make sure | |
# it's executable. | |
# Add whatever you need to load your app environment to a .preload.rb in the | |
# base directory of your project. | |
# Add #!/usr/bin/env ruby_preload as the first line of any script you want to |
This file contains 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 "net/http" | |
# fetcher = FeedCrawler::URLFetcher.new("example.com") | |
# paths = ["/foo", "/bar", "/baz", "/qux"] | |
# results = fetcher.fetch(paths) | |
# results.each do |result| | |
# puts result | |
# end | |
# | |
class URLFetcher |
This file contains 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 "socket" | |
# edit these | |
socket_path = "tmp/sockets/unicorn.sock" | |
host = "example.com" # HTTP 1.1 requires a Host header | |
path = "/" | |
# connect | |
sock = UNIXSocket.new(socket_path) |
This file contains 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
// dimensions should be the number of dimensions your points have | |
// points should be an array of arrays, the inner arrays representing points | |
// depth shouldn't be passed, it's used internally | |
// example: | |
// var tree = kdtree(2, [[1,2], [3,4], [5,6]]); | |
function kdtree(dimensions, points, depth) { | |
depth = depth || 0; | |
var axis = depth % dimensions, | |
node = {axis: axis}; |
This file contains 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
# simple recursive algorithm | |
def binary_search_recursive(ary, value) | |
return nil if ary.empty? | |
pivot = ary.length / 2 | |
pivot_value = ary[pivot] | |
if pivot_value < value | |
binary_search_recursive(ary[(pivot + 1)..-1], value) | |
elsif pivot_value == value | |
return pivot | |
else |
This file contains 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 sh | |
set -e | |
dot_env=`cat .env` | |
env $dot_env $@ |
This file contains 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 "net/http/persistent" | |
require "net/http/pipeline" | |
class DeferredProxy < BasicObject | |
def initialize(&generator) | |
@generator = generator | |
end | |
def method_missing(*args, &block) | |
@source ||= @generator.call |
This file contains 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 "time" | |
# Usage: | |
# | |
# SphinxQueryLog.each("path/to/query.log") do |entry| | |
# # do stuff with entry | |
# end | |
# | |
class SphinxQueryLog |
This file contains 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
# Ruby 2.0.0 preview 1 highlights | |
# A few examples of the highlights given in | |
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/46348 | |
# Refinements | |
# =========== | |
# create a namespaced refinement | |
module NumberQuery |