Skip to content

Instantly share code, notes, and snippets.

@carolineartz
carolineartz / documents.rb
Last active July 19, 2019 16:44 — forked from dhh/documents.rb
dhh Rails resource example
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@carolineartz
carolineartz / ticket.rb
Created February 13, 2016 00:03 — forked from dhh/ticket.rb
class Ticket < ActiveRecord::Base
belongs_to :grouper
belongs_to :user
validate :user_cant_be_blacklisted, on: :confirmation
validate :user_cant_double_book, on: :confirmation
validate :grouper_cant_be_full, on: :confirmation
validate :grouper_cant_have_occurred, on: :confirmation
@carolineartz
carolineartz / server.sh
Created February 3, 2016 16:37 — forked from MohamedAlaa/server.sh
osx computer info in terminal
#!/bin/bash
echo "--------------------------------------------------------------------------------"
uname -a
echo "--------------------------------------------------------------------------------"
MEMORY=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Memory' | awk '{print $1 $2 $3}'`
echo "$MEMORY"
echo "--------------------------------------------------------------------------------"
CORES_COUNT=`sysctl hw.ncpu | awk '{print $2}'`
echo "CPU"
sysctl -n machdep.cpu.brand_string
@carolineartz
carolineartz / powder_down.md
Created January 28, 2016 20:16
powder down without password

Put this in your shell startup file (.zshrc, etc). the \r is required after your password to execute the carriage return

function powder_down() {
expect <<EOF
spawn /Users/<yourname>/.rbenv/shims/powder down
expect {
  "Password:" { send "<password here>\r"; exp_continue }
  eof
}
@carolineartz
carolineartz / advanced_commadline_grocery_list.rb
Last active February 1, 2016 14:10
Example Solution for Students -- Dev Bootcamp Guided Pairing 2.2: Create an Electronic Grocery List
# Advanced solution w/ commandline input
#
def new_list
{}
end
def add(item, quantity, list)
return list[item] = quantity unless list[item]
puts "#{item.upcase} is already on your list! Use command `update` to change the quantity."
end
@carolineartz
carolineartz / .aprc
Created January 10, 2016 02:01
.aprc
AwesomePrint.defaults ||= {}
AwesomePrint.defaults.merge!(
indent: 2
)
AwesomePrint.defaults[:color] ||= {}
AwesomePrint.defaults[:color].merge!(
class: :yellowish,
method: :blueish,
args: :blue,
# ENHANCED CONSOLE OUTPUT
#
# Adds directories to load path so that `require` can locate and source
GEM_PATH = '/Users/caroline.artz/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/'
$LOAD_PATH.push(GEM_PATH + 'awesome_print-1.6.1/lib/',
GEM_PATH + 'unicode_utils-1.4.0/lib/',
GEM_PATH + 'coolline-0.5.0/lib/',
GEM_PATH + 'pry-coolline-0.2.5/lib/',
GEM_PATH + 'coderay-1.1.0/lib/')
@carolineartz
carolineartz / grocery_list.rb
Last active October 7, 2015 04:11 — forked from celeen/grocery_list.rb
for DBC Phase 0 coaching
# Requirements
#
# Create a new list
# Add an item with a quantity to the list
# Remove an item from the list
# Update quantities for items in your list
# Print the list (Consider how to make it look nice!)
# Pseudocode
  • something
  • something done
require 'forwardable'
GroceryItem = Struct.new(:name, :quantity, :in_cart) do
def to_s
text = "#{quantity} : #{name}"
in_cart ? "√ #{text}" : " #{text}"
end
end