Skip to content

Instantly share code, notes, and snippets.

View timuruski's full-sized avatar
🏳️‍⚧️
Protect Trans Rights

Tim Uruski timuruski

🏳️‍⚧️
Protect Trans Rights
View GitHub Profile
#! /usr/bin/ruby
LBRACE = '{'
RBRACE = '}'
LBRACKET = '['
RBRACKET = ']'
COMMA = ','
COLON = ':'
WHITESPACE = /\s/
@timuruski
timuruski / migratory-habits.markdown
Last active August 29, 2015 13:58
Notes for a talk about Rails migrations

The Migratory Habits of Rails Developers

Table of contents:

  • migration tasks
  • new change syntax
  • using models in a migration
  • reversible migrations
  • revert command

The ABCs of Ruby

  • A is for ARGF
  • B is for blocks
  • C is for CSV
  • D is for DBM (Database Management library) or Dir or DATA
  • E is for Enumerable and Enumerators
  • F is for Fibers
  • G is for GServer
  • H is for Hash
@timuruski
timuruski / squeeze.rb
Created March 21, 2014 16:59
Not sure what to call this type of operation.
# Input
events = [
event(status: 'IDLE', job: 1, date: '2014-01-01'),
event(status: 'BUSY', job: 1, date: '2014-01-02'),
event(status: 'BUSY', job: 1, date: '2014-01-03'),
event(status: 'BUSY', job: 2, date: '2014-01-04'),
event(status: 'BUSY', job: 2, date: '2014-01-05'),
event(status: 'BUSY', job: 2, date: '2014-01-06'),
event(status: 'IDLE', job: 2, date: '2014-01-07'),
event(status: 'BUSY', job: 3, date: '2014-01-08'),
@timuruski
timuruski / bash_profile
Created March 12, 2014 14:20
Portable bash profile with a nice prompt
# PROMPT
# ==========
PS1="\[\e[33m\]\h\[\e[0m\]:\[\e[4m\]\W\[\e[0m\] \$ "
# ALIASES
# =========
alias ls="ls -lh"
@timuruski
timuruski / bench-sort.rb
Last active August 29, 2015 13:56
Benchmarking sort strategies in Ruby.
require 'benchmark'
a = Array.new(10_000) { rand }
Benchmark.bm(20) do |bench|
bench.report('sort <=>') { 10.times { a.sort { |x,y| y <=> x } } }
bench.report('sort.reverse') { 10.times { a.sort.reverse } }
bench.report('sort_by.reverse') { 10.times { a.sort_by(&:to_f).reverse } }
end
$ which ruby
> /Users/timuruski/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
$ time ~/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -e "1 + 1"
> ~/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -e "1 + 1" 0.03s user 0.01s system 93% cpu 0.034 total
$ time /usr/bin/ruby -e "1 + 1"
> /usr/bin/ruby -e "1 + 1" 0.00s user 0.00s system 73% cpu 0.005 total
class Address
include ActiveResource::Attributes
string :street_address, :street_address_2, :street_address_3, :leave_location,
:city, :province_state, :country, :name, :phone_number, :special_instructions,
:postal_zipcode, :leave_location, :company, :special_instructions, :attention_name
boolean :is_residential, :addressable
end
# PROMPT
# ==========
# This doesn't work?
status () {
if [[ $? -gt 0 ]]; then
printf "\[\e[31m\]\$\[\e[0m\]"
else
printf "\$"
fi
class CustomerList
def initialize(account, filter = nil)
@account = account
@filter = filter
end
# That's right, attributes after initializer.
attr_reader :account, :filter
end