Skip to content

Instantly share code, notes, and snippets.

Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript
powered JS and SASS powered CSS with YUI compression all via the magic of rack.
This stuff will be native in Rails 3.1 and the layout of the files on the
filesystem will be different but this guide will get you working with it
while we wait for all that to finalize.
Ignore the number prefixes on each file. This is just to ensure proper order in the Gist.
It's based on eric1234 gist https://gist.github.com/911003. ijust made it 3.1 compliant in terms of convention
@latentflip
latentflip / random_words.rb
Created May 16, 2011 17:09
Random list of words
words = File.read('/usr/share/dict/words').split
(1..10).each do
puts words[rand(words.length)]
end
#=> uncessant
rumor
deontology
engross
@latentflip
latentflip / golf.rb
Created May 23, 2011 18:26 — forked from morganp/golf.rb
L/SH/ScotRug Code Golf
g=Golf=Hash
def g.method_missing s, a
k=[]
case s.to_s[-1]
when ?1
a.reduce :*
when ?2
a.split.sort_by{|i| i[1] }*' '
when ?3
h1 1..a
@latentflip
latentflip / macspoof.sh
Created June 3, 2011 20:10
MAC Spoof on OSX
### Do these once
ifconfig en1|grep ether > .macaddress #Save your real mac address somewhere
#Alias the airport adapter
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport
###Then each time you want to change MAC address:
airport -z #disconnect but don't turn off the airport
sudo ifconfig en1 ether 00:00:00:00:00:00 #set new mac address (perhaps just increment your old one)
ifconfig en1|grep ether #check it's actually changed
<script type="text/javascript">
var a_function = function() {
var a_number = 2;
document.write('Within a_function, a_number = '+a_number+'<br>');
return function(a) {
document.write('Within the callback, a_number = '+a_number+'<br>');
document.write('Within the callback, I was passed = '+a+'<br>');
document.write('Within the callback, a * a_number = '+a*a_number+'<br>');
@latentflip
latentflip / wordpress2tumblr.rb
Created July 17, 2011 10:07 — forked from webcracy/wordpress2tumblr.rb
A script to import your Wordpress posts on Tumblr
# Export your Wordpress posts to Tumblr (also allows to delete some.)
# Author: Alexandre Solleiro <[email protected]>
# How-to:
# 1. Export your Wordpress posts (http://en.blog.wordpress.com/2006/06/12/xml-import-export/)
# 2. Edit the information below to match your settings
# 3. To import, type "ruby wordpress2tumblr.rb --run" in the command line
# 4. To delete some posts, type "ruby wordpress2tumblr.rb --delete 1,2,3,4" where 1,2,3,4 are post numbers. (Be careful not to use spaces between IDs)
# Edit these
WP_EXPORT_PATH = "./wordpress.2009-09-14.xml" # path to the Wordpress Export file
"hello" === "hello #true
String("hello") === "hello" #true
new String("hello") === "hello" #false
new String("hello") == "hello" #true
@latentflip
latentflip / aggregations.md
Created November 18, 2011 13:19
Before save and active record association aggregations

So today I learned that if you have:

class Invoice < ActiveRecord::Base
  has_many :transactions
  before_save :cache_transaction_total

  def cache_transaction_total
    self.transaction_total = transactions.sum(:total) || 0
  end

end

@latentflip
latentflip / Rakefile
Created January 9, 2012 17:44
A better Rakefile for rails?
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
#Load all the tasks in lib/tasks
Dir[File.expand_path('../lib/tasks/', __FILE__) + '/*.rake'].each do |file|
load file
end
#The original rails rakefile loading
@latentflip
latentflip / gist:2170114
Created March 23, 2012 12:11
CoffeeScript sytax

If we try and use parens only for precedence, not arg passing:

$('#contact_form').submit -> validate this

becomes

($ '#contact_form').submit -> validate this

which almost makes sense