Skip to content

Instantly share code, notes, and snippets.

@the8472
the8472 / ci.rb
Created August 28, 2014 17:48
Continuous building for firefox addons
#!/usr/bin/ruby
require "rubygems"
gem "rb-inotify"
require "rb-inotify"
notifier = INotify::Notifier.new
event_handler = proc do
puts "change detected, running CI"
buildView: function() {
let window = windowUtils.getMostRecentBrowserWindow();
let doc = window.document;
let content = doc.getElementById("appcontent");
let splitter = doc.createElementNS(XUL_NS, 'splitter');
splitter.setAttribute("resizeafter","closest")
splitter.setAttribute("resizebefore","closest")
@the8472
the8472 / gist:ae462c8f8d598a7be671
Created April 22, 2015 00:51
JMH bench for custom executor
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
@the8472
the8472 / gist:1952018
Created March 1, 2012 18:38
Make CanCan 1.6 + arel 2.0 work with multiple scopes
require "cancan/model_adapters/active_record_adapter"
class CanCan::ModelAdapters::ActiveRecordAdapter
# disable the error when multiple conditions with scopes are used
def override_scope
return false
end
# convert where-clauses from relations into sql strings which will be merged by the cancan merge_conditions logic
@the8472
the8472 / gist:2312198
Created April 5, 2012 16:06
MonkeyPatch CanCan to use OUTER JOINs (requires squeel)
require "cancan/model_adapters/active_record_adapter"
class CanCan::ModelAdapters::ActiveRecordAdapter
# use squeel's symbol-predicates to convert all joins into outer joins
# see https://github.com/ryanb/cancan/issues/374
def clean_joins(joins_hash)
joins = []
joins_hash.each do |name, nested|
name = name.outer if nested.is_a? Hash
joins << (nested.empty? ? name : {name => clean_joins(nested)})
@the8472
the8472 / cancan_initializer.rb
Created June 18, 2012 12:59
MonkeyPatch for cancan#646
require "cancan/model_adapters/active_record_adapter"
class CanCan::ModelAdapters::ActiveRecordAdapter
def merge_conditions(sql, conditions_hash, behavior)
conditions_hash = Squeel::Nodes::Literal.new(conditions_hash) if conditions_hash.is_a? String
if conditions_hash.blank?
Squeel::Nodes::Literal.new(behavior ? true_sql : false_sql)
else
case sql
require 'active_record'
class ReferencedModelA < ActiveRecord::Base; end
class ReferencedModelB < ActiveRecord::Base; end
class ReferencedModelC < ActiveRecord::Base; end
class ModelA < ActiveRecord::Base
has_many :referenced_model_a
end
@the8472
the8472 / cancan_squeel_extension.rb
Created November 8, 2012 16:11
outerjoin fixes + rails 3.2.8 compat + scope merging for cancan, using squeel
# encoding: UTF-8
require "cancan/model_adapters/active_record_adapter"
class CanCan::Rule
def unmergeable?
false
end
end
module Mhmr::DescendantsTracker
def descendants_and_self
[self].concat self.descendants
end
end
ActiveSupport::DescendantsTracker.send(:include,Mhmr::DescendantsTracker)
jruby:
@the8472
the8472 / minimal testing up
Created December 12, 2012 16:28
Rails startup performance tuning with jruby. Note that those settings are *not* for optimal steady state operation.
### ruby 1.9.3 + railsexpress patches + GC tuning + -march=native -O3
time ruby script/rails r 'Post.count'
real 0m1.008s
user 0m0.820s
sys 0m0.180s
### jruby 1.7.2-dev 2012-12-12 + java 64bit 1.8.0-ea-b67 hotspot 25.0-b11