Skip to content

Instantly share code, notes, and snippets.

View luislavena's full-sized avatar

Luis Lavena luislavena

View GitHub Profile
@luislavena
luislavena / gist:954581
Created May 4, 2011 01:12
VS2010 (x64) vs GCC 4.5.1 (x86), GCC 4.5.3 (x86) and GCC 4.5.3 (x64) - Pointless microbenchmarks
# i386-mingw32: RubyInstaller
# x64-mswin64_100: Arton's NougakuDo (http://www.artonx.org/data/nougakudo/index.html)
# x64-mingw32: Experimental 64bits RubyInstaller
ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
time elapsed: 10.772616 sec.
time elapsed: 10.782617 sec.
time elapsed: 10.796617 sec.
time elapsed: 10.754615 sec.
time elapsed: 10.824619 sec.
C:\Users\Luis\Projects\_sandbox\ruby-perf>ruby -v require_benchmark.rb
ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
user system total real
500 requires 0.078000 0.202000 0.280000 ( 0.283016)
1000 requires 0.187000 0.375000 0.562000 ( 0.575033)
1500 requires 0.265000 0.624000 0.889000 ( 0.900051)
2000 requires 0.515000 0.780000 1.295000 ( 1.292074)
2500 requires 0.686000 1.076000 1.762000 ( 1.773102)
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
@kdonovan
kdonovan / apn_sender
Created June 17, 2011 01:04
Contents of the file apn_sender's generator puts in script/apn_sender (for those on Rails 3, where the generator isn't working yet)
#!/usr/bin/env ruby
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'apn'
require 'apn/sender_daemon'
APN::SenderDaemon.new(ARGV).daemonize
@karmi
karmi / geo_distance_filter_in_tire.rb
Created June 28, 2011 14:13
Geo Distance Filter Support in Tire/ElasticSearch
require 'tire'
require 'active_support/core_ext/numeric'
require 'active_support/core_ext/time/zones'
# Tire.configure { logger STDERR, level: 'debug' }
class Time; DATE_FORMATS.update lucene: "%Y-%m-%dT%H:%M"; end
Tire.index 'venues' do
@stereobooster
stereobooster / test_env_path.rb
Created July 16, 2011 23:49
Information about environment path
executables = {}
total = 0
path_extensions = ENV["PATHEXT"].gsub(".", "").downcase.split(File::PATH_SEPARATOR)
path = ENV["Path"]
path.split(File::PATH_SEPARATOR).each do |value|
dir = Pathname.new(value)
if dir.exist? then
filter = File.join(dir.realpath, "*.{" + path_extensions.join(",") + "}")
Dir.glob(filter).each do |file|
@foca
foca / value_object.rb
Created July 30, 2011 02:14
Extremely lightweight "Struct" that only defines attribute readers
module ValueObject
def self.new(*attrs)
klass = Class.new(Object)
klass.send(:attr_reader, *attrs)
klass.send(:define_method, :initialize) do |*args|
raise ArgumentError, "wrong number of arguments (#{args.size} for #{attrs.size})" unless args.size == attrs.size
attrs.each_with_index do |attr, idx|
instance_variable_set("@#{attr}", args[idx])
require "benchmark"
TESTS = 10_000
puts "File.expand_path: #{TESTS} times."
Benchmark.bmbm do |results|
results.report("Ruby '':") { TESTS.times { File.expand_path('') } }
results.report("Ruby '.':") { TESTS.times { File.expand_path('.') } }
require 'minitest/autorun'
class Subject < Struct.new(:lol)
def render_controls
lol.button_to 'Vote'
end
end
describe 'lolwot' do
it "should generate a button" do
ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]
rails 3.1.1
C:\>rails new empty-187 -d sqlite3
C:\empty-187>timer ruby script\rails runner "puts $LOADED_FEATURES.size"
705
real 4.538
system 2.667
user 1.794
@shirosaki
shirosaki / file_access.patch
Created December 5, 2011 09:39
tma sample
diff --git a/samples/file_access.cpp b/samples/file_access.cpp
new file mode 100644
index 0000000..1ea02e3
--- /dev/null
+++ b/samples/file_access.cpp
@@ -0,0 +1,108 @@
+#include <ios>
+#include <iostream>
+#include <ostream>
+#include <iomanip>