This file contains hidden or 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 Boolean | |
def self.from_json(value) | |
if value.is_a?(TrueClass) || value.is_a?(FalseClass) | |
return value | |
elsif value.is_a?(String) | |
return value == ("true" || "1") | |
elsif value.is_a?(Integer) | |
return value == 1 | |
else | |
nil |
This file contains hidden or 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
form_block = proc do |has_many_form| | |
form_block_contents = "".html_safe | |
index = parent_child_index options[:parent] if options[:parent] | |
form_block_contents << (block.call(has_many_form, index) || "".html_safe) | |
form_block_actions = has_many_actions(has_many_form, builder_options, "".html_safe) | |
form_block_contents << form_block_actions | |
template.concat(form_block_actions) | |
form_block_contents | |
end |
This file contains hidden or 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' | |
gem 'nokogiri' | |
require 'nokogiri' | |
def validate(document_path, schema_path, root_element) | |
schema = Nokogiri::XML::Schema(File.read(schema_path)) | |
document = Nokogiri::XML(File.read(document_path)) | |
schema.validate(document.xpath("//#{root_element}").to_s) | |
end | |
This file contains hidden or 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
# h = ActiveSupport::OrderedOptions.new | |
# h.boy = 'John' | |
# h.girl = 'Mary' | |
# h.boy # => 'John' | |
# h.girl # => 'Mary' | |
class OrderedOptions < Hash | |
alias_method :_get, :[] # preserve the original #[] method | |
protected :_get # make it protected | |
def []=(key, value) |
This file contains hidden or 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 "faraday" | |
require 'typhoeus' | |
conn = Faraday.new(:url => 'http://httpstat.us') do |builder| | |
builder.request :url_encoded | |
builder.response :logger | |
builder.adapter :typhoeus | |
end | |
conn.in_parallel do |
This file contains hidden or 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 'bundler' | |
require 'fileutils' | |
require 'net/http' | |
require 'net/https' | |
require 'uri' | |
TMP_DIR = "/tmp/gems" |
This file contains hidden or 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
{"data"=>[{"id"=>"526", "type"=>"termination_cdrs", "links"=>{"self"=>"http://www.example.com/api/rest/public/termination_cdrs/526"}, "attributes"=>{"time_start"=>"2016-11-02T11:44:00.485Z", "time_connect"=>"2016-11-02T11:44:00.485Z", "time_end"=>"2016-11-02T11:49:00.489Z", "duration"=>nil, "aleg_code"=>nil, "aleg_reason"=>nil, "src_name_in"=>nil, "src_number_in"=>nil, "dst_number_in"=>nil, "orig_call_id"=>nil, "billing_duration"=>nil, "billing_rate"=>nil, "billing_connection_fee"=>nil, "billing_initial_interval"=>nil, "billing_next_interval"=>nil, "billing_price"=>nil}}, {"id"=>"527", "type"=>"termination_cdrs", "links"=>{"self"=>"http://www.example.com/api/rest/public/termination_cdrs/527"}, "attributes"=>{"time_start"=>"2016-11-02T11:44:00.529Z", "time_connect"=>"2016-11-02T11:44:00.529Z", "time_end"=>"2016-11-02T11:49:00.532Z", "duration"=>nil, "aleg_code"=>nil, "aleg_reason"=>nil, "src_name_in"=>nil, "src_number_in"=>nil, "dst_number_in"=>nil, "orig_call_id"=>nil, "billing_duration"=>nil, "billing_rate"= |
This file contains hidden or 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 String | |
def words | |
scan(/\w[\w\'\-]*/) | |
end | |
end |
This file contains hidden or 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
#template for select option, I use it to show regions and draw country flags for each city | |
cityOptionTpl = (obj)-> | |
_.tpl('CitySelectOption')(obj) | |
#helper for rendering option | |
renderCityOption = (entry)-> | |
tplRes = cityOptionTpl({it: | |
title : entry.title | |
region : entry.region | |
country_name : entry.country_name |