Skip to content

Instantly share code, notes, and snippets.

View al2o3cr's full-sized avatar

Matt Jones al2o3cr

View GitHub Profile
@al2o3cr
al2o3cr / regex_bench.rb
Created April 23, 2011 16:01
Regex benchmarks
require 'benchmark'
nelements = 10
nlines = 10
def repeating_string(base, elements, lines)
(([base]*elements).join(',')+"\n")*lines
end
# test string
GC.start
first_count = ObjectSpace.each_object(String) { |x| nil }
def dummy_function
'foo'
end
second_count = ObjectSpace.each_object(String) { |x| nil }
GC.start
second_after_gc_count = ObjectSpace.each_object(String) { |x| nil }
@al2o3cr
al2o3cr / test_case.rb
Created September 20, 2015 17:54
inverse_of regression in 4.2
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# NOTE: tests pass on 4.1.x, fail on 4.2
<def tag="tabs">
<set-scoped tab-names="&[]" tab-contents="&{}">
<ul class="tabs" merge>
<do param="default" />
</ul>
<do repeat="&scope.tab_names">
<div id="#{this}">
<%= scope.tab_contents[this] %>
</div>
</do>
<def tag="page" attrs="title, full-title">
<% full_title ||= "#{title} : #{app_name}" %>
<html merge-attrs>
<head param>
<title param><%= strip_tags full_title %></title>
<stylesheet name="reset" />
<do param="scripts">
<javascript param name="prototype, effects, dragdrop, controls, lowpro, hobo-rapid"/>
<if-ie version="lt IE 7" param="fix-ie6">
en:
reservations:
messages:
create:
success: "The appointment was created successfully"
error: "Couldn't create the appointment. #{errors}"
update:
success: "Changes to the appointment were saved"
<ul id="menunav">
<% Page.main_pages.each do |page| -%>
<li style="width: 90px;">
<% if page.redirect? -%>
<%= link_to page.navlabel, {:action => page.action_name, :controller => page.controller_name, :name => page.name} -%>
<% else -%>
<%= link_to page.navlabel, view_page_path(page.name) %>
<% unless page.sub_pages.empty? -%>
<ul>
<% page.sub_pages.each do |subpage| -%>
module Outer
module M
def foo
if self.class.superclass.instance_methods.include?('foo')
super
else
puts 'module foo'
end
end
end
<def tag="js-wrapper" attrs="convert">
<set-scoped vals="&[]">
<do param="default" />
<% if convert %>
<%= "[#{scope.vals.*.inspect.join(', ')}]" %>
<% else %>
<% scope.retval = scope.vals %>
<% end %>
</set-scoped>
</def>
@al2o3cr
al2o3cr / test_associations.rb
Created September 3, 2015 00:48
Attempted repro for rails/rails #21466
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'activerecord', '4.2.4'