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
#ruby | |
require "rubygems" | |
require "net/http" | |
require 'nokogiri' | |
#API | |
PARAMS = %w(title website description) | |
API_KEY = "YOUR KEY" | |
LOCATION = "moscow" |
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 Module | |
def fields_callbacks(fields) | |
fields.each do |field, value| | |
class_eval do | |
alias :"old_#{field}=" :"#{field}=" | |
define_method("#{field}=") do |v| | |
value.each { |method| send(method) } | |
send("old_#{field}=", v) | |
end | |
end |
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
source 'http://rubygems.org' | |
gem 'sinatra' | |
gem 'haml' |
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 Array | |
def my_own_inject(proc) | |
temp = 0 | |
self.each do |e| | |
temp = proc.call(temp, e) | |
end | |
temp | |
end | |
end |
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 Integer | |
def odd? | |
% 2 == 0 | |
end | |
end | |
def middle_index(input) | |
size = input.size | |
if size.odd? | |
size/2 |
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
$("input[type='checkbox']").each(function(){ | |
$(this).attr('checked', true); | |
}); |
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
# assert_equal "あいうえお".unpack('__'), [12354, 12356, 12358, 12360, 12362] | |
['S', 'L', 'Q', 'c', 's', 'l', 'q', 'S_', 'S!', 'I', 'I_', 'I', 'L_', 'L!', 's_', 's!', 'i', 'i_', 'i', 'l_', 'l!', 'S>', 'L>', 'Q>', 's>', 'l>', 'q>', 'S!>', 'I!>', 'L!>', 's!>', 'i!>', 'l!>', 'S<', 'L<', 'Q<', 's<', 'l<', 'q<', 'S!<', 'I!<', 'L!<', 's!<', 'i!<', 'l!<', 'n', 'N', 'v', 'V', 'U', 'w', 'a', 'A', 'Z', 'B', 'b', 'H', 'h', 'u', 'M', 'm', 'P', 'p', '@', 'x', 'X', 'D', 'd', 'F', 'f', 'E', 'e', 'G', 'g'].each do |a| | |
begin | |
p "あいうえお".unpack("#{a}*") | |
rescue | |
end | |
end |
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 'test/unit' | |
include Test::Unit::Assertions | |
class Array | |
def transpose | |
return [] if empty? | |
a = Array.new(self.first.size) {[]} | |
each do |e| | |
begin |
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
h = {} | |
h[:label] = "Red" | |
h_copy = h | |
h_dup = h.dup | |
h_clone = h.clone | |
h_deep_copy = Marshal.load( Marshal.dump h ) | |
p h[:label].object_id # => 2156268500 | |
p h_dup[:label].object_id # => 2156268500 |
OlderNewer