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
module Ova | |
# autovivifying map from [class][method][signature] to Method | |
@@Ova = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } | |
# Wrap #respond_to? for parity with Class#===. | |
Responder = Struct.new(:method) do | |
def === obj | |
obj.respond_to?(method) | |
end | |
end |
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
class Array | |
# Returns a proc which calls [] with the array's contents as arguments | |
# | |
# ====Usage | |
# [[1, 2], [3, 4], [5, 6]].map(&[0]) | |
# # => [1, 3, 5] | |
# | |
# [{ hello: 'world' }, { hello: 'sun', goodbye: 'moon' }].map(&[:hello]) | |
# # => ['world', 'sun'] |
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
## | |
# This is rake task of padrino-framework | |
# Display lists of all stacked rack middleware for your padrino app. | |
# distributed under the MIT License(http://tyabe.mit-license.org/) | |
# | |
def stacked_middlewares(app, args) | |
require Padrino.root('config/boot.rb') | |
app_obj = app.app_obj | |
instance = app_obj.new! | |
build = app_obj.build(instance) |
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
Sequel.migration do | |
up do | |
run 'CREATE EXTENSION "uuid-ossp"' | |
create_table :products do | |
column :id, :uuid, :default => Sequel.function(:uuid_generate_v4), :primary_key => true | |
end | |
end | |
end |
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
# Ways to execute a shell script in Ruby | |
# Example Script - Joseph Pecoraro | |
cmd = "echo 'hi'" # Sample string that can be used | |
# 1. Kernel#` - commonly called backticks - `cmd` | |
# This is like many other languages, including bash, PHP, and Perl | |
# Returns the result of the shell command | |
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111 |
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 'tire' | |
# Tire.configure { logger STDERR, level: 'debug' } | |
Tire.index('movie-titles') do | |
delete | |
create \ | |
settings: { | |
index: { | |
analysis: { |
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
FILE SPACING: | |
# double space a file | |
sed G | |
# double space a file which already has blank lines in it. Output file | |
# should contain no more than one blank line between lines of text. | |
sed '/^$/d;G' |
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 | |
# encoding: utf-8 | |
require 'memory_profiler' | |
gem 'redis', ENV['RVERSION'] | |
require 'redis' | |
puts Process.pid | |
puts Redis::VERSION |
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" | |
def start_server | |
# Remove the X to enable the parameters for tuning. | |
# These are the default values as of Ruby 2.2.0. | |
@child = spawn(<<-EOC.split.join(" ")) | |
XRUBY_GC_HEAP_FREE_SLOTS=4096 | |
XRUBY_GC_HEAP_INIT_SLOTS=10000 | |
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8 | |
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0 |
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
CREATE UNLOGGED TABLE exclude_test(id integer primary key); | |
INSERT INTO exclude_test(id) SELECT generate_series(1,50000); | |
CREATE UNLOGGED TABLE exclude AS SELECT x AS item FROM generate_series(1,40000,4) x; | |
-- Horrific AND list, takes 80s to plan and execute here: | |
EXPLAIN ANALYZE SELECT id FROM exclude_test WHERE id <> 1 AND id <> 5 AND id <> 9 AND id <> 13 AND id <> 17 AND id <> 21 AND id <> 25 AND id <> 29 AND id <> 33 AND id <> 37 AND id <> 41 AND id <> 45 AND id <> 49 AND id <> 53 AND id <> 57 AND id <> 61 AND id <> 65 AND id <> 69 AND id <> 73 AND id <> 77 AND id <> 81 AND id <> 85 AND id <> 89 AND id <> 93 AND id <> 97 AND id <> 101 AND id <> 105 AND id <> 109 AND id <> 113 AND id <> 117 AND id <> 121 AND id <> 125 AND id <> 129 AND id <> 133 AND id <> 137 AND id <> 141 AND id <> 145 AND id <> 149 AND id <> 153 AND id <> 157 AND id <> 161 AND id <> 165 AND id <> 169 AND id <> 173 AND id <> 177 AND id <> 181 AND id <> 185 AND id <> 189 AND id <> 193 AND id <> 197 AND id <> 201 AND id <> 205 AND id <> |
OlderNewer