Skip to content

Instantly share code, notes, and snippets.

View matthuhiggins's full-sized avatar

Matthew Higgins matthuhiggins

View GitHub Profile
@matthuhiggins
matthuhiggins / Gemfile
Created May 29, 2012 21:43
cassandra interaction
source "http://rubygems.org"
gem 'mcmire-cassandra', require: 'cassandra/1.0'
@matthuhiggins
matthuhiggins / braintree.rb
Created April 13, 2012 16:10
Using Object#tap to create scopes
Braintree::Configuration.tap do |config|
if settings = YAML.load_file(Rails.root.join('config', 'braintree.yml'))[Rails.env]
config.environment = :sandbox
config.merchant_id = settings['merchant_id']
config.public_key = settings['public_key']
config.private_key = settings['private_key']
end
end
@matthuhiggins
matthuhiggins / gist:1998191
Created March 8, 2012 02:38
delayed query
function SearchPlaces(inputSelector) {
var input = $(inputSelector).hintInput(),
baseUrl = input.attr('data-source');
function currentQuery() {
if (input.hasClass('empty')) {
return '';
} else {
return input.val();
}
if ARGV.size != 2
puts "usage: cassandra_tokens.py <current_size> <new_size>"
exit
end
CURRENT_NODES = ARGV[0].to_i
GOING_TO_NODES = ARGV[1].to_i
RING_SIZE = 2**127
def tokens(node_count)
require 'uri'
require 'net/http'
require 'net/https'
module Curl
class Easy
attr_accessor :uri, :headers, :follow_location, :max_redirects
attr_accessor :response, :redirect_count
def initialize
@matthuhiggins
matthuhiggins / Questions
Created August 8, 2011 23:46
Frozen Rails Give-away
Day job: Web/Mobile Developer @ GoTime
Your Rails contributions: Gems https://rubygems.org/profiles/2519
What's your Ruby/Rail experience?: 4 years, working almost always with Rails.
How do you use GitHub?: Private hosting for work and public hosting for open source
@matthuhiggins
matthuhiggins / hash.rb
Created December 25, 2010 02:16
ruby 1.9 hash
sweet_hash = {
foo: "bar",
faz: "baz"
}
@matthuhiggins
matthuhiggins / create_table_1.rb
Created November 27, 2010 00:07
mysql_love_2
create_table :foo, :id => false do |t|
t.column :id, :manual_pk
t.column :bytes, :big_integer
end
@matthuhiggins
matthuhiggins / faster.rb
Created November 27, 2010 00:02
mysql_love_3
def tag_list
self.tags.calculate(:group_concat, :name)
end
@matthuhiggins
matthuhiggins / faster.sql
Created November 26, 2010 23:58
mysql_love_1
INSERT INTO tags(name, post_tags_count, created_at, updated_at) VALUES ('latin', utc_timestamp, utc_timestamp, 1) ON DUPLICATE KEY UPDATE updated_at = utc_timestamp, post_tags_count = post_tags_count + 1, id=LAST_INSERT_ID(id)
INSERT INTO tags(name, post_tags_count, created_at, updated_at) VALUES ('illegible', utc_timestamp, utc_timestamp, 1) ON DUPLICATE KEY UPDATE updated_at = utc_timestamp, post_tags_count = post_tags_count + 1, id=LAST_INSERT_ID(id)
INSERT INTO tags(name, post_tags_count, created_at, updated_at) VALUES ('rails', utc_timestamp, utc_timestamp, 1) ON DUPLICATE KEY UPDATE updated_at = utc_timestamp, post_tags_count = post_tags_count + 1, id=LAST_INSERT_ID(id)
SELECT * FROM `tags` WHERE (`tags`.`id` IN (1,2,3)
INSERT INTO `posts` (`created_at`, `updated_at`, `text`) VALUES('2008-07-04 23:17:20', '2008-07-04 23:17:20', 'Lorem ipsum dolor sit amet...')
INSERT INTO `post_tags` (`tag_id`, `post_id`) VALUES(1, 1)
INSERT INTO `post_tags` (`tag_id`, `post_id`) VALUES(2, 1)
INSERT INTO `post_tags` (`t