Skip to content

Instantly share code, notes, and snippets.

View guilleiguaran's full-sized avatar
💭

Guillermo Iguaran guilleiguaran

💭
View GitHub Profile
@guilleiguaran
guilleiguaran / active_model_compliant.rb
Created July 21, 2011 06:06
Ohm::ActiveModelCompliant, allows to Ohm (Redis OHM) to be partially compliant with ActiveModel (except errors)
require 'active_model'
module Ohm
module ActiveModelCompliant
def self.included(base)
base.send(:extend, ActiveModel::Naming)
base.send(:include, ActiveModel::Conversion)
base.send(:include, InstanceMethods)
end
@guilleiguaran
guilleiguaran / singleton_foo.rb
Created August 5, 2011 15:49
Hacking Object.new to ensure that only one instance of an object exists in memory
# Don't use this in a real project never!!!
class SingletonFoo < Object
def self.new(*args)
first_instance = ObjectSpace.each_object(self).first
return first_instance if first_instance
object = allocate
object.send(:initialize, *args)
object
end
end
@guilleiguaran
guilleiguaran / actionpack.log
Created August 6, 2011 09:02
Rails tests under rbx 2.0
1) Failure:
test_using_hash_resource(RespondWithControllerTest)
[/Users/guille/code/rails/actionpack/test/controller/mime_responds_test.rb:659:in `test_using_hash_resource'
/Users/guille/code/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in `run'
/Users/guille/code/rails/activesupport/lib/active_support/callbacks.rb:426:in `_run_setup_callbacks'
/Users/guille/code/rails/activesupport/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/guille/code/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:65:in `run'
kernel/bootstrap/array.rb:66:in `each'
kernel/bootstrap/array.rb:66:in `each']:
<"{\"result\":{\"name\":\"david\",\"id\":13}}"> expected but was
@zliang-min
zliang-min / high_function.scala
Created August 10, 2011 09:49
Use scala high functions in JRuby!
object HighFunction {
def foo(num : Int)(f : Int => Int) = f(num)
}
@kbarber
kbarber / gist:1139540
Created August 11, 2011 12:37
Running Ruby code in C
#include <stdio.h>
#include <ruby.h>
int main(int argc, char *argv[]) {
// Open file
FILE *fp;
fp = fopen(argv[1], "r");
if(fp == NULL) {
return 1;
require 'rubygems'
require 'java'
require 'mvn:org.clojure:clojure'
require 'mvn:org.clojure:clojure-contrib'
require 'clojure-jsr223'
java_import 'javax.script.ScriptEngineManager'
factory = ScriptEngineManager.new
engine = factory.get_engine_by_name 'Clojure'
@javan
javan / gist:1168475
Created August 24, 2011 16:32
Fix iPhone home button
Found this tip in comment here: http://www.tipb.com/2011/01/04/tipb-bug-home-button-working-iphone/
1.) Open any application
2.) Press and hold the power button until the slide to shutdown swipe bar appears.
3.) Release Power button
4.) Press and hold Home button Lightly
until screen returns to icon screen
@igrigorik
igrigorik / Gemfile
Created August 26, 2011 06:33
HTML5 SSE / EventSource demo with Goliath
source :gemcutter
gem 'goliath', :git => 'git://github.com/postrank-labs/goliath.git'
gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git'
@guilleiguaran
guilleiguaran / assets.rake
Created September 1, 2011 04:26
Fixed rake assets:precompile task
desc "Compile all the assets named in config.assets.precompile"
task :precompile do
# We need to do this dance because RAILS_GROUPS is used
# too early in the boot process and changing here is already too late.
if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
ENV["RAILS_GROUPS"] ||= "assets"
ENV["RAILS_ENV"] ||= "production"
Kernel.exec $0, *ARGV
else
Rake::Task["environment"].invoke
require 'thread'
require 'json'
require 'net/http'
require 'uri'
require 'betabrite'
require 'psych'
require 'usb'
class StreamClient
def initialize user, pass