Skip to content

Instantly share code, notes, and snippets.

View tenderlove's full-sized avatar
©️
 ​[object Object] :trollface:

Aaron Patterson tenderlove

©️
 ​[object Object] :trollface:
View GitHub Profile
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)
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!
@tenderlove
tenderlove / meta.rb
Created September 26, 2008 18:32 — forked from jbarnette/meta.rb
require "rubygems"
require "johnson"
require "./visitor.rb"
js =<<-END
function top() {
"top docstring", { command: true }
doSomething();
};
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)
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 {
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 {
####
# 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]
####
# ( ++ 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
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
####
# Morse code for ruby
#
# puts ( +-~+-~+-+~---~-+ M ) # => 'aaron'
#
class M
DITS_N_DAHS = {
'+-' => 'a',
'-+++' => 'b',
'-+-+' => 'c',