Skip to content

Instantly share code, notes, and snippets.

@christineyen
christineyen / cron.rake
Created May 14, 2011 02:30
Heroku -> S3 Backup rake task
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
Rake::Task['heroku:backup'].invoke
end
@christineyen
christineyen / gist:1016536
Created June 9, 2011 11:10
Using the multipart-post gem to POST a file to Crocodoc
# via https://github.com/nicksieger/multipart-post's README, with a tweak to force SSL
require 'net/http/post/multipart'
uri = URI.parse('https://crocodoc.com/api/v1/document/upload')
res = File.open('./tmp/filename.jpg', 'rb') do |file|
req = Net::HTTP::Post::Multipart.new(uri.path,
'file' => UploadIO.new(file, nil),
'token' => APP_CONFIG['crocodoc_token'])
http = Net::HTTP.new(uri.host, uri.port)
@christineyen
christineyen / form_helper.rb
Created June 15, 2011 09:12
Snippets of Rails source for reference in blog
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
fields_options, record_object = record_object, nil if record_object.is_a?(Hash)
fields_options[:builder] ||= options[:builder]
fields_options[:parent_builder] = self
case record_name
when String, Symbol
if nested_attributes_association?(record_name)
return fields_for_with_nested_attributes(record_name, record_object, fields_options, block)
end
@christineyen
christineyen / 00000_create_users.rb
Created June 15, 2011 10:04
Nested form for a serialized has_many relationship
class AddBillItemsToUsers < ActiveRecord::Migration
def self.up
add_column :users, :bill_items, :string
end
def self.down
remove_column :users, :bill_items
end
end
@christineyen
christineyen / hack.sh
Created May 1, 2012 19:51 — forked from emcmanus/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@christineyen
christineyen / actionSheetStandard.m
Created May 3, 2012 21:05
Framework vs. BlocksKit handling, for blog
- (IBAction)clickedCloseButton:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Discard post?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Discard"
otherButtonTitles:@"Save draft", nil];
[actionSheet showInView:self.view];
}
// UIActionSheetDelegate methods
@christineyen
christineyen / exceptional.m
Created October 23, 2012 00:19
GCD and @try/@catch, for blog
@try {
dispatch_async(dispatch_get_main_queue(), ^{
[NSException raise:NSGenericException format:@"uncaught exception!"];
});
} @catch (NSException *exception) {
// USELESS
}
@christineyen
christineyen / gist:4153497
Created November 27, 2012 10:23
cassandra experimentation
## via shell:
## fetches + runs the correct version of Cassandra for you
# CASSANDRA_VERSION=1.1 cassandra_helper cassandra
## via CLI:
# create keyspace Parse with placement_strategy='org.apache.cassandra.locator.SimpleStrategy' AND strategy_options = [{ replication_factor: 1 }];
# use Parse;
# via irb:
@christineyen
christineyen / _intro.md
Created November 28, 2012 00:26
cassandra benchmarking

How should I think of the efficiency of a single operation? If there is one row that we are incrementing 10 counters in, will that cost about as much as incrementing a single counter in that row, or more like 10x?

(Note: Updating the same row n times, without batching, produces the same numbers as any other n operations without batching.)

$ go test -bench=. regcmp_test.go
testing: warning: no tests to run
BenchmarkNegativeMatchBool-8 10000000 118 ns/op
BenchmarkNegativeMatchString-8 10000000 128 ns/op
BenchmarkPositiveMatchBool-8 1000000 2494 ns/op
BenchmarkPositiveMatchString-8 500000 2878 ns/op
PASS
ok command-line-arguments 6.718s