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
var data = {}; | |
var options = {}; | |
options.type = 'POST'; | |
options.url = url; | |
options.dataType = 'json'; | |
options.cache = false; | |
options.data = jq.toJSON(data); | |
options.contentType = 'application/json; charset=utf-8'; | |
options.success = function(){}; |
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 InstanceExec | |
Code = lambda do | |
unless Object.new.respond_to?(:instance_exec) | |
module InstanceExecHelper; end | |
include InstanceExecHelper | |
def instance_exec(*args, &block) | |
begin | |
old_critical, Thread.critical = Thread.critical, true | |
n = 0 |
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
# In response to: | |
# http://mlomnicki.com/ruby/tricks-and-quirks/2011/02/10/ruby-tricks2.html | |
# Ruby 1.9.2 has some neat stuff that lets us make a readable | |
# alternative case statement that calls each method in turn. | |
# 1.9.2 features used: | |
# * hashes are ordered in 1.9.2 | |
# * cool JSON-style hash syntax | |
# * concise lambda syntax |
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
Net::HTTP.get(URI.parse('http://twitter.com/#!/jcasts/statuses/34647787559718912')) | |
BEGIN { | |
require 'net/http' |
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
def tip(msg); puts; puts msg; puts "-"*100; end | |
# | |
# 30 Ruby 1.9 Tips, Tricks & Features: | |
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/ | |
# | |
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2" | |
tip "Ruby 1.9 supports named captures in regular expressions!" |
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
# I want this method in ruby-core | |
def let | |
yield | |
end | |
def fib(i) | |
let do |n = 1, result = 0| | |
if i == -1 | |
result | |
else |
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
#! /usr/bin/env ruby | |
Main { | |
description <<-____ | |
mp3scrape will scour any url for it's mp3 content - the script mirrors, | |
never downloading the same file twice. it does not, however, crawl a | |
website for links, it simple scapes all the songs from a single page. |
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
<!-- layout file --> | |
<% if current_user %> | |
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %> | |
<% else %> | |
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>. | |
<% 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
// a solution to http://blog.abhiomkar.in/2010/07/03/javascript-code-challenge-by-dropbox-team/ | |
// | |
var countdown = function(num){ | |
for (var i = 0; i <= num; i += 1) { | |
(function(i){ setTimeout(function(){ alert(num - i); }, i * 1000); })(i); | |
} | |
} | |
countdown(5); |
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
desc "a task which creates the database user" | |
task(:createuser) do | |
require 'yaml' | |
require 'erb' | |
path = File.join(Rails.root, 'config', 'database.yml') | |
config = YAML::load(ERB.new((IO.read(path))).result) | |
config = config[Rails.env] || config | |
adapter = config['adapter'] | |
username = config['username'] | |
password = config['password'] |