This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module JsonMethods | |
def json_methods(attributes) | |
define_method(:to_json_with_mode) do |mode = :default| | |
methods = attributes[mode] | |
elements = [] | |
case methods | |
when Array | |
elements = methods.map { |method| JsonMethods.jsonify_element(method, self.send(method), mode) } | |
when Hash | |
elements = methods.map { |key, method| JsonMethods.jsonify_element(key, self.send(method), mode) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [:method_one, :method_two] | |
# [[:method_one, :other_method_one]] | |
# [[:method_one, :other_method_one, :other_method_two], :method_two] | |
# [{ :methodOne => :method_one, :methodTwo => :method_two }] | |
# [{ :methodOne => [:method_one, :other_method_one, :other_method_two], :methodTwo => :method_two }] | |
# [{ :methodOne => [:method_one, { :otherMethodOne => :other_method_one }], :methodTwo => :method_two }] | |
module ToHash | |
def self.eval_object(object, attributes) | |
if object.kind_of?(Array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 06ae0d5c71cf9c5d06badd4927d59f4fe821d1c8 Mon Sep 17 00:00:00 2001 | |
From: =?utf-8?q?Jakub=20Ku=C5=BAma?= <kuba@synergypeople.net> | |
Date: Tue, 26 May 2009 10:29:17 +0200 | |
Subject: [PATCH] fixed field_set_and_list_wrapping_for_method to use join | |
--- | |
lib/formtastic.rb | 2 ++ | |
1 files changed, 2 insertions(+), 0 deletions(-) | |
diff --git a/lib/formtastic.rb b/lib/formtastic.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rubygems" | |
require "daemons" | |
INTERFACE = "wlan0" | |
TEST_ADDRESSES = %w(http://www.google.pl/ http://www.yahoo.com/ http://www.msn.com/) | |
TEST_TIMEOUT = 5 | |
SCAN_TIMEOUT = 1 | |
CONNECTION_TIMEOUT = 30 | |
LOOP_DELAY = 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "nokogiri" | |
require "uri" | |
module Rack | |
class KarmaChameleon | |
def initialize(app, options = {}) | |
@ext = options[:extension] || "aspx" | |
@ext_regexp = /\.#@ext$/ | |
@app = app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gist test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Proxy < defined?(BasicObject) ? BasicObject : Object | |
instance_methods.each { |m| undef_method(m) if m.to_s !~ /^__/ } | |
def initialize(target, options = {}, &block) | |
@proxy_owner = options[:owner] | |
@proxy_target = target | |
extends = Array(options[:extend]) | |
extends << ::Module.new(&block) | |
extends.each { |m| m.send(:extend_object, self) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /javascripts/i18n/:locale.js | |
# /javascripts/i18n/:locale.js | |
# /public/javascripts/i18n/:locale.js | |
require "json" | |
MINIFIED_LIB = <<EOJS | |
var I18n=I18n||(function(){function a(g,f){return g.replace(/\{\{([^}]+)\}\}/g,function(){return f[arguments[1]]||arguments[0]})}function c(f){if(!f){return[]}if(typeof f!="string"){return f}return f.split(".")}function d(g,j){var f=0,h=I18n.translations;j=(typeof j==="string")?[j]:(j||[]);while(g[f]){h=h&&h[g[f]];f++}if(h){return h}else{if(j.length===0){return null}else{if(j[0].substr(0,1)===":"){return d(g.slice(0,g.length-1).concat(c(j[0].substr(1))),j.slice(1))}else{return j[0]}}}}function b(g,f){if(f===undefined){return g}return f===1?g.one:g.other}function e(j,g){if(typeof j!="string"){var f=[],h;for(h=0;h<j.length;h++){f.push(e(j[h],g))}return f}else{g=g||{};g.defaultValue=g.defaultValue||null;j=c(g.scope).concat(c(j));var k=d(j,g.defaultValue);if(typeof k!=="string"&&k){k=b(k,g.count)}if(typeof k==="string"){k=a(k,g)}return k}}return{translate:e,t:e}})(); | |
EOJS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
require "rack/contrib/simple_endpoint" | |
MINIFIED_LIB = <<EOJS | |
var I18n=I18n||(function(){function a(g,f){return g.replace(/\{\{([^}]+)\}\}/g,function(){return f[arguments[1]]||arguments[0]})}function c(f){if(!f){return[]}if(typeof f!="string"){return f}return f.split(".")}function d(g,j){var f=0,h=I18n.translations;j=(typeof j==="string")?[j]:(j||[]);while(g[f]){h=h&&h[g[f]];f++}if(h){return h}else{if(j.length===0){return null}else{if(j[0].substr(0,1)===":"){return d(g.slice(0,g.length-1).concat(c(j[0].substr(1))),j.slice(1))}else{return j[0]}}}}function b(g,f){if(f===undefined){return g}return f===1?g.one:g.other}function e(j,g){if(typeof j!="string"){var f=[],h;for(h=0;h<j.length;h++){f.push(e(j[h],g))}return f}else{g=g||{};g.defaultValue=g.defaultValue||null;j=c(g.scope).concat(c(j));var k=d(j,g.defaultValue);if(typeof k!=="string"&&k){k=b(k,g.count)}if(typeof k==="string"){k=a(k,g)}return k}}return{translate:e,t:e}})(); | |
EOJS | |
class RackjsMiddleware < Rack::SimpleEndpoint | |
def initialize(ap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_body # Net::HTTPResponse#read_body | |
yield "foo"; yield "bar"; yield "baz" | |
end | |
class R # A Rack Streaming response | |
def initialize | |
@l = lambda do |block| | |
read_body do |chunk| # Net::HTTPResponse#read_body | |
sleep(0.5) | |
block.call(chunk) |