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 "set" | |
| module RakeTask | |
| CALLED = Set.new | |
| NAMESPACES = [] | |
| TASKS = Hash.new { |h, k| h[k] = Struct.new(:blocks, :deps).new([], []) } | |
| class << self | |
| def call(name) | |
| return if CALLED.include?(name) |
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 CommentsTest < NodeTestCase | |
| def test_line_numbers | |
| parser = RKelly::Parser.new | |
| ast = parser.parse(<<-eojs) | |
| /** | |
| * This is an awesome test comment. | |
| */ | |
| function aaron() { // This is a side comment | |
| var x = 10; | |
| return 1 + 1; // America! |
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 "johnson" | |
| require "./visitor.rb" | |
| js =<<-END | |
| function top() { | |
| "top docstring", { command: true } | |
| doSomething(); | |
| }; |
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 'rubygems' | |
| require 'builder' | |
| require 'benchmark' | |
| n = 50_000 | |
| Benchmark.bm(7) do |x| | |
| x.report("builder: ") { | |
| n.times { | |
| builder = Builder::XmlMarkup.new(:indent => 1) |
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 'rubygems' | |
| require 'builder' | |
| require 'benchmark' | |
| require 'faster_builder/xml_markup' | |
| n = 50_000 | |
| Benchmark.bm(7) do |x| | |
| x.report("builder: ") { | |
| n.times { |
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 'rubygems' | |
| require 'benchmark' | |
| require 'faster_builder/xml_markup' | |
| n = 50_000 | |
| Benchmark.bm(7) do |x| | |
| x.report("nokogiri: ") { | |
| n.times { | |
| Nokogiri::XML::Builder.new { |
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
| #### | |
| # Get the dimensions for a Jpeg | |
| # | |
| class JpegFile | |
| def initialize file | |
| @io = File.open(file, 'rb') | |
| end | |
| def dimensions | |
| raise 'Not a jpeg' unless @io.read(2).unpack('CC') == [0xFF, 0xD8] |
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
| #### | |
| # ( ++ B ).to_i #=> 3 | |
| # ( ++- B ).to_i #=> 6 | |
| # ( ++-+ B ).to_i #=> 13 | |
| # ( 0 + ++-+ B ) #=> 13 | |
| class B | |
| class << self | |
| def +@; new.send(:"+@"); end | |
| def -@; new.send(:"-@"); 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
| module Color | |
| class RGB < Struct.new(:r, :g, :b) | |
| def to_hsl | |
| (r,g,b) = *([self.r, self.g, self.b].map { |x| x / 255.0 }) | |
| min = [r,g,b].min | |
| max = [r,g,b].max | |
| l = (max + min) / 2.0 | |
| return HSL.new(0, 0, (l * 100).round) if max == min | |
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
| #### | |
| # Morse code for ruby | |
| # | |
| # puts ( +-~+-~+-+~---~-+ M ) # => 'aaron' | |
| # | |
| class M | |
| DITS_N_DAHS = { | |
| '+-' => 'a', | |
| '-+++' => 'b', | |
| '-+-+' => 'c', |
OlderNewer