View rails_erb_syntax_check.rb
require 'action_view'
require 'tmpdir'
require 'fileutils'
require 'optparse'
def check_syntax(path, options = {})
erb = content(path)
code = ruby_code(erb)
eval("BEGIN { puts('ok'); return true }; #{code}", nil, path, 0)
View serializer_benchmarks.rb
# sudo gem install bson
# sudo gem install bson_ext
# sudo gem install yajl-ruby
# sudo gem install json
# sudo gem install msgpack
require 'rubygems'
require 'benchmark'
require 'yaml'
require 'bson'
View explain.txt
mysql> EXPLAIN SELECT `my_table_name_xxxxxxxxxxxxx`.* FROM `my_table_name_xxxxxxxxxxxxx` WHERE `my_table_name_xxxxxxxxxxxxx`.`order_id` = 2015522 LIMIT 1;
+----+-------------+-----------------------------+------+-----------------------------------------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------------------------+------+-----------------------------------------------+------+---------+------+--------+-------------+
| 1 | SIMPLE | my_table_name_xxxxxxxxxxxxx | ALL | index_my_table_name_xxxxxxxxxxxxx_on_order_id | NULL | NULL | NULL | 280511 | Using where |
+----+-------------+-----------------------------+------+-----------------------------------------------+------+---------+------+--------+-------------+
1 row in set (0.00 sec)
mysql> EXPLAIN SELECT `my_table_name_xxxxxxxxxxxxx`.* FROM `my_table_name_xx
View low_level.rb
client = Elasticsearch::Client.new host: 'localhost:9200', logger: Rails.logger
client.indices.create({
index: "businesses",
body: {
settings: {},
mappings: {
"business" => {
properties:{
name: {:type=>"string", index: "not_analyzed"}, # you probably need different index type depending on what kind of queries there are
View 1.rb
# keep in one file
class Whatever
class A
def self.interface_method
end
end
class B
def self.interface_method
end
View log.txt
==> p: Last 10 log lines:
==> p: compiling object_tracing.c
==> p: compiling objspace.c
==> p: linking shared-object objspace.so
==> p: make[2]: Leaving directory `/tmp/ruby-build.20141225212618.1716/ruby-2.2.0/ext/objspace'
==> p: linking shared-object date_core.so
==> p: make[2]: Leaving directory `/tmp/ruby-build.20141225212618.1716/ruby-2.2.0/ext/date'
==> p: linking shared-object nkf.so
==> p: make[2]: Leaving directory `/tmp/ruby-build.20141225212618.1716/ruby-2.2.0/ext/nkf'
==> p: make[1]: Leaving directory `/tmp/ruby-build.20141225212618.1716/ruby-2.2.0'
View dead.rb
class DeadCodeConcern
def self.dead_code_or_not_dead_code?(name)
notify_honeybadger_not_dead_code(name)
notify_logger_not_dead_code(name)
end
def self.notify_honeybadger_not_dead_code(name)
Honeybadger.notify( StandardError.new("Not dead code: #{name}") )
end
View m1.txt
evil:Inventory#change_quantity:/home/rupert/ssd/rupert/develop/paneq/inventory-mutation/lib/inventory.rb:18:a2bf6
@@ -1,8 +1,8 @@
def change_quantity(identifier, qty)
if (((qty - @reserved_quantity[identifier].sum) - @sold_quantity[identifier].sum) < 0)
- raise(StandardError, "quantity too low")
+ raise
end
@available_quantity[identifier] << (-@available_quantity[identifier].last)
@available_quantity[identifier] << qty
end
View bench.rb
require 'benchmark'
ActiveRecord::Base.logger = nil
Benchmark.bmbm do |bench|
bench.report("SQL query") do
1000.times { Whatever.count }
end
bench.report("exception hit") do
View gist:94fe211ad68b13027ffd
class IssuesController < ApplicationController
default_search_scope :issues
before_filter :find_issue, :only => [:show, :edit, :update]
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
before_filter :find_project, :only => [:new, :create, :update_form]
before_filter :authorize, :except => [:index]
before_filter :find_optional_project, :only => [:index]
before_filter :check_for_default_issue_status, :only => [:new, :create]
before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]