Skip to content

Instantly share code, notes, and snippets.

#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}
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)
@ayosec
ayosec / pocket.rake
Created January 28, 2011 11:39
Xiraxi - AssetPocket
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|
@ayosec
ayosec / gems.md
Created March 2, 2011 17:32
Gems collection
$ 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
# >---------------------------[ 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|
@ayosec
ayosec / gist:902825
Created April 5, 2011 01:12
Downloader for TED
# 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 = []
@ayosec
ayosec / github-add-every-repo-in-network.rb
Created April 27, 2011 00:54
Nasty way to add every fork of a GitHub repository
#!/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
# Firebug console
>>> var j = [0];
undefined
>>> j == !j
true
>>> j === !j
false
// 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);