Skip to content

Instantly share code, notes, and snippets.

View gstark's full-sized avatar

Gavin Stark gstark

View GitHub Profile
@gstark
gstark / set.rb
Created July 14, 2012 06:19
using |= to merge collections into sets is inefficient, the correct way is to use #merge
# This shows that set |= collection creates a NEW set with the resulting
# members which is slightly inefficient. #merge does the same thing
# without creating a new Set object
require 'set'
set = Set.new([1,2,3,4])
puts "set is: #{set.inspect} and Object ID before |= is #{set.object_id}"
Started POST "/redacted/redacted" for 173.65.43.25 at Thu Jul 12 06:39:04 -0400 2012
NativeException (java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/torquebox/datasources/
app-knob.yml/production):
" noremap <silent> ,cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
" noremap <silent> ,cu :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>
# Hash keyed by y to speed to_s
def to_h
hash_with_default = Hash.new {|hash,key| hash[key] = []}
@points.inject(hash_with_default) { |hash, point| h[point.y] << point.x; hash }
end
@gstark
gstark / gist:2571816
Created May 1, 2012 22:06
gstvideoscale_patch.diff
diff --git a/gst/videoscale/gstvideoscale.c b/gst/videoscale/gstvideoscale.c
index 7b44647..5618b37 100644
--- a/gst/videoscale/gstvideoscale.c
+++ b/gst/videoscale/gstvideoscale.c
@@ -307,6 +307,7 @@ gst_video_scale_class_init (GstVideoScaleClass * klass)
static void
gst_video_scale_init (GstVideoScale * videoscale, GstVideoScaleClass * klass)
{
+ GST_DEBUG("GES: calling video scale init");
videoscale->tmp_buf = NULL;
require 'benchmark'
n = 5_000_000
find = 4
array = [1,2,3,4]
Benchmark.bm do |x|
x.report { n.times { array.include?(4) } }
x.report { n.times { array.include?(5) } }
x.report { n.times { [1,2,3,4].include?(5) } }
#
# Having #process dependent on File.open
# *and* #read, separate the processing to allow a
# more general IO processing and another method
# that handles the opening to get the IO and delegate
#
describe "Processing XML file" do
it "Reads from a file and processes the contents" do
file_path = "/some/path/to.xml"
stub_io = stub
case something
when value1
command1
command2
command3
when value2
command4
command5
when value3
command6
((rand().to_i)...rand((rand(5000).to_i))).send(Enumerable.instance_methods[rand(Enumerable.instance_methods.size)]) { rand(6) > 2 }
BOOL canCustomize = No;
canCustomize = [self.cust....] ||
[self.cust....] ||
[self.cust....] ||
[self.cust....] ||
[self.cust....] ||
[self.cust....];
return canCustomize;