Some interesting gems to consider.
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
#layout | |
.calendar | |
- current_date = Date.new(@current_year, 1, 1) | |
- while current_date.year == @current_year | |
- if current_date.day == 1 | |
%table.month | |
%thead | |
%tr.month-name | |
%th{:colspan => 7} |
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
module Kernel | |
def trace_instances(traced_class = ActiveRecord::Base, &block) | |
instances = [] | |
set_trace_func(proc do |event, file, line, id, binding, classname| | |
if event == "line" | |
obj = eval("self", binding) | |
instances << obj if obj.kind_of?(traced_class) | |
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
paths = Rails.application.railties.engines.map {|e| e.root } | |
paths.push Rails.root | |
# Load every stylesheet in application.css | |
sass "public/stylesheets/application.css" do | |
# First load the basics/*.scss and then the rules | |
["basics/", ""].each do |prefix| | |
paths.reverse.each do |path| |
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
$ wc -c application.js | |
49209 application.js | |
$ time java -jar ~/.javascript_closure_compiler/compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS < application.js | wc | |
50 263 22969 | |
real 0m3.022s | |
user 0m2.888s | |
sys 0m0.108s |
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
# >---------------------------[ Install Command ]-----------------------------< | |
# rails new APP_NAME -m https://gist.github.com/raw/858810/gistfile1.rb -O -J | |
# >---------------------------------------------------------------------------< | |
# | |
# This template was based on http://railswizard.org | |
# | |
# >----------------------------[ Initial Setup ]------------------------------< | |
initializer 'generators.rb', <<-RUBY | |
Rails.application.config.generators do |g| |
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
# Use | |
# ruby download.rb http://www.ted.com/search?q=any+query | |
require 'rubygems' | |
require 'mechanize' | |
agent = Mechanize.new { |agent| agent.user_agent_alias = 'Linux Firefox' } | |
pages = ARGV | |
loaded = [] |
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
#!/usr/bin/env ruby | |
# Nasty way to add every fork of a GitHub repository | |
if ARGV.size != 2 | |
puts "Use: #$0 owner repository" | |
exit 1 | |
end | |
current_remotes = File.read(".git/config").scan(/\[remote "(.*?)"\]/).flatten |
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
# Firebug console | |
>>> var j = [0]; | |
undefined | |
>>> j == !j | |
true | |
>>> j === !j | |
false |
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
// Generates a click on the first element returned by document.querySelector("#foo") | |
// The main idea is to activate all the event handlers asociated to the node | |
// https://developer.mozilla.org/en/DOM/event.initMouseEvent | |
// http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mouseevents | |
click_event = document.createEvent("MouseEvents"); | |
click_event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
document.querySelector("#foo").dispatchEvent(click_event); |