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' | |
| require 'parse_tree' | |
| require 'ruby2ruby' | |
| require 'sexp_processor' | |
| require 'ruby_parser' | |
| class Codes | |
| def super_awesome | |
| foo = 10 | |
| foo + 10 * 20 |
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 | |
| #### | |
| # Generate a dot file graphing of all gems that *depend on* ARGV[0] | |
| require 'rubygems' | |
| require 'yaml' | |
| puts("#{$0} <gemname>") || exit(1) unless ARGV[0] | |
| file = 'yaml.marshal' |
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 'nokogiri' | |
| class Nokogiri::XML::Node | |
| def method_missing name, *args, &block | |
| list = xpath("//#{name}") | |
| list.length == 1 ? list.first : list | |
| end | |
| end | |
| doc = Nokogiri::HTML(<<-eohtml) |
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' | |
| require 'nokogiri' | |
| class Nokogiri::XML::Node | |
| def method_missing name, *args, &block | |
| if args.empty? | |
| list = xpath("./#{name}") | |
| elsif args.first.is_a? Hash | |
| hash = args.first | |
| if hash[:css] |
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
| # Monkey patch for faster net/http io | |
| class Net::BufferedIO #:nodoc: | |
| alias :old_rbuf_fill :rbuf_fill | |
| def rbuf_fill | |
| begin | |
| @rbuf << @io.read_nonblock(65536) | |
| rescue Errno::EWOULDBLOCK | |
| if IO.select([@io], nil, nil, @read_timeout) | |
| @rbuf << @io.read_nonblock(65536) | |
| else |
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 'nokogiri' | |
| require 'open-uri' | |
| doc = Nokogiri::XML(open('http://search.twitter.com/search.atom?q=%22Black+Friday%22')) | |
| doc.xpath('//ns:title', { 'ns' => 'http://www.w3.org/2005/Atom' }).each do |title| | |
| puts title | |
| 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
| require 'rubygems' | |
| require 'nokogiri' | |
| class EyeTunes | |
| attr_reader :tracks | |
| def initialize file | |
| @artists = Hash.new { |artists,artist| | |
| artists[artist] = Hash.new { |albums,album| | |
| albums[album] = Hash.new { |tracks,track| |
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
| #### | |
| # How online advertising happens | |
| # | |
| # all_the_fibonacci_numbers_in_one_hash contains all of the fibonacci numbers | |
| # in one hash. | |
| all_the_fibonacci_numbers_in_one_hash = Hash.new { |h,k| | |
| h[k] = k < 2 ? k : h[k - 1] + h[k - 2] | |
| } | |
| 0.upto(10) do |i| |
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
| gem 'mechanize', '>=0.9.0' | |
| require 'mechanize' | |
| ### | |
| # Log in to itunes connect, get the list of applications. | |
| # | |
| # Example: | |
| # | |
| # ITunesConnect.new do |client| | |
| # client.login 'user@example.com', 'password' |
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 'johnson' | |
| require 'rubygems' | |
| require 'nokogiri' | |
| doc = Nokogiri::HTML(<<-eohtml) | |
| <html> | |
| <head> | |
| <script> | |
| function populateForm() { | |
| var select = document.getElementsByTagName("select").item(0); |