Skip to content

Instantly share code, notes, and snippets.

View chaslemley's full-sized avatar

Chas Lemley chaslemley

  • Airbnb
  • Atlanta, Ga
View GitHub Profile
$(function(){
Movie = Backbone.Model;
var Movies = Backbone.Collection.extend({
model: Movie,
url: '/movies'
});
MovieController = Backbone.Controller.extend({
routes: {
(1..100).each do |num|
str = ""
str << "Fizz" if num % 3 == 0
str << "Buzz" if num % 5 == 0
str = num if str.empty?
print str
print ", " if num < 100
@chaslemley
chaslemley / dynamoDB_example.rb
Created January 23, 2012 15:17
Example of using Amazon's DynamoDB to store user activity
require "aws-sdk"
class Dynamo
attr_accessor :attributes
def initialize(hash)
raise ArgumentError, "argument passed to .new must be a Hash" unless hash.is_a? Hash
raise ArgumentError, "hash must contain key :#{self.class.hash_key}" unless hash.has_key? self.class.hash_key.to_sym
raise ArgumentError, "hash must contain key :#{self.class.range_key}" unless self.class.has_range_key? && hash.has_key?(self.class.range_key.to_sym)
@attributes = {}
@chaslemley
chaslemley / trace.rb
Created January 24, 2012 15:35
Accessing --verbose and --trace from within a Rake command
puts "ran with trace" if Rake.application.options.trace == true
Before:
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 3276 | 2474 | 50 | 249 | 4 | 7 |
| Helpers | 329 | 268 | 0 | 36 | 0 | 5 |
| Models | 5594 | 4084 | 73 | 462 | 6 | 6 |
| Libraries | 1293 | 1057 | 21 | 121 | 5 | 6 |
| Model specs | 5784 | 4553 | 0 | 34 | 0 | 131 |
@chaslemley
chaslemley / resque_retire.rb
Created September 5, 2012 15:14
Retire Resque Workers
retired_hosts = %w{ip-10-30-154-136 ip-11-30-159-135}
Resque::workers.map do |worker|
host = worker.id.split(":").first
if retired_hosts.include? host
worker.unregister_worker
end
end
<DocuSignEnvelopeInformation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.docusign.net/API/3.0">
<EnvelopeStatus>
<EnvelopeID>fdsafdsa</EnvelopeID>
</EnvelopeStatus>
</DocuSignEnvelopeInformation>
{:available_on=>Tue, 13 May 2014, :display_total_price=>false, :hotel_id=>1255, :id=>1332736, :room_type_id=>1, :sold_out=>false, :sold_out_at=>nil, :available_nights=>[{:num_nights=>1, :num_remaining=>1, :customer_net_price=>300, :customer_tax_amount=>49, :customer_gross_price=>349, :customer_net_price_average=>300, :customer_tax_amount_average=>49, :customer_gross_price_average=>349, :customer_regular_net_price=>nil, :customer_regular_tax_amount=>nil, :customer_regular_gross_price=>nil}, {:num_nights=>2, :num_remaining=>1, :customer_net_price=>300, :customer_tax_amount=>49, :customer_gross_price=>349, :customer_net_price_average=>150, :customer_tax_amount_average=>24, :customer_gross_price_average=>174, :customer_regular_net_price=>nil, :customer_regular_tax_amount=>nil, :customer_regular_gross_price=>nil}, {:num_nights=>3, :num_remaining=>1, :customer_net_price=>300, :customer_tax_amount=>49, :customer_gross_price=>349, :customer_net_price_average=>100, :customer_tax_amount_average=>16, :customer_gross_pri
[redshift]
Description = ODBC for Redshift
Driver = PostgreSQL
Database = dbname
Servername = servername.redshift.amazonaws.com
Port = 5439
Debug = 1