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
# Usage: | |
# ruby -rubygems json2csv.rb my-dump.json > people.csv | |
# | |
require 'json'; require 'csv' | |
FIELDS = %w(id screen_name name friends_count followers_count) | |
data = JSON.load ARGF | |
csv = CSV::Writer.create(STDOUT) | |
data.each { |user| csv << FIELDS.map { |f| user[f] } } |
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
> This is a Shortwave configuration file | |
> http://shortwaveapp.com/ | |
> | |
> Some triggers copied from benpickles (http://gist.github.com/43371) | |
> | |
> Urls may contain the following replacement tokens: | |
> | |
> %s → search terms | |
> %r → URL of current page | |
> %d → domain part of the current URL |
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
## requires will_paginate "agnostic" branch | |
class NiftyRenderer < WillPaginate::ViewHelpers::LinkRenderer | |
protected | |
def pagination | |
[:previous_page, :nifty_info, :next_page] | |
end | |
def nifty_info |
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
class Page | |
include DataMapper::Resource | |
belongs_to :crawl | |
property :id, Serial | |
property :uri, URI | |
property :body, Text, :length => 65535 | |
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
[alias] | |
conflicts = !git ls-files --unmerged | cut -c51- | sort -u | xargs $EDITOR | |
resolve = !git ls-files --unmerged | cut -c51- | sort -u | xargs git add |
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
What did you do to get good at Rails? | |
Read source code, wrote plugins | |
Who taught you what you know? | |
Josh Susser! (about ActiveRecord) | |
Do you have any fond (or not so fond) memories of your learning experiences? |
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
require 'dm-core' | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'sqlite3::memory:') | |
class User | |
include DataMapper::Resource | |
has n, :follows | |
has n, :followings, :model => 'Follow', :child_key => [:target_id] |
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 -rubygems | |
## solving Railscast #190 with Nibbler | |
## http://github.com/mislav/nibbler | |
## http://railscasts.com/episodes/190-screen-scraping-with-nokogiri | |
require 'nokogiri' | |
require 'open-uri' | |
require 'nibbler' | |
class Walmart < Nibbler |
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 update_counter(record, *names) | |
updates = names.each_with_object({}) do |name, memo| | |
counter = "#{name}_count" | |
diff = record.send(name).count - record.send(counter) | |
memo[counter] = diff unless diff.zero? | |
end | |
record.class.update_counters(record.id, updates) if updates.any? | |
end | |
Community.paginated_each(:per_page => 100) do |record| |
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
require 'active_record' | |
class ActiveRecord::Base | |
def self.magic! | |
connection.tables.map { |table| | |
klass = Class.new(self) | |
Object.send(:const_set, table.singularize.camelize, klass) | |
}.each { |model| | |
model.column_names.grep(/_id$/).each { |foreign_key| | |
name = foreign_key.sub(/_id$/, '') |