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
headers = [] | |
File.open("/path/to/file.tsv") do |file| | |
file.each_line do |line| | |
data = line.split(/\t/) | |
if headers.empty? | |
headers = data | |
else | |
data = Hash[*headers.zip(data).flatten] | |
MyModel.create(data) |
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 | |
# Heavily based on https://github.com/ip2k/twitter-avatar-update | |
# ==== Gems ==== | |
require 'twitter_oauth' | |
require 'oauth' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'yaml' |
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 ActiveRecord::Base | |
attr_accessible nil | |
def update_attributes *args | |
raise "Don't call #{self.class.name}#update_attributes. " + | |
"Mass assignment is pure evil." | |
end | |
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
class PrimeFactor | |
def initialize(number) | |
@factors = Fiber.new do | |
divisor = 2 | |
while divisor < number | |
while number % divisor == 0 | |
Fiber.yield divisor | |
number = number / divisor | |
end | |
divisor = divisor + 1 |
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 | |
# code2png - Render code to an image on OS X | |
# Peter Cooper (@peterc) | |
# MIT license | |
# | |
# code2png converts source code into a PNG graphic | |
# (with syntax coloring, if you want). Ideal for | |
# Kindle document production, RSS feeds, etc. | |
# |
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
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: unicorn | |
# Required-Start: $local_fs $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: unicorn initscript | |
# Description: Unicorn is an HTTP server for Rack application | |
### END INIT 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
cmd: >>>sudo -u foo PATH=/usr/local/bin:/usr/bin:/bin sh -c "cd /home/foo && pwd"<<< | |
/home/foo: 1: Syntax error: Unterminated quoted string |
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 | |
# A simply utility to show character counts for each line of input and | |
# highlight lines longer than 80 characters. | |
# | |
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html | |
# | |
# Examples: | |
# | |
# $ hilong Gemfile |
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 Invoice < ActiveRecord::Base | |
has_many :line_items | |
end | |
class LineItemTemplate < ActiveRecord::Base | |
has_many :criteria | |
end | |
class Criteria < ActiveRecord::Base | |
belongs_to :line_item_template |
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 output name=((default=true); "caius") | |
puts "name: #{name.inspect}" | |
puts "default: #{default.inspect}" | |
end | |
output | |
# >> name: "caius" | |
# >> default: true | |
output "avdi" |