Skip to content

Instantly share code, notes, and snippets.

View jcasimir's full-sized avatar

Jeff Casimir jcasimir

View GitHub Profile
puts "What is your favorite number?"
favenum = gets.chomp
# Using Interpolation
puts "Well that looks great, but wouldn't #{favenum.to_i + 1} be better?"
# Using Concatenation
puts "Well that looks great, but wouldn't " + (favenum.to_i + 1).to_s + "be better?"
@jcasimir
jcasimir / toc.rb
Created April 18, 2011 22:40 — forked from racbarn/toc.rb
line_width = 25
begin
puts 'Table of Contents'.center(line_width)
puts 'Chapter 1: Intro'.ljust(line_width) + 'page 1'.rjust(line_width)
puts 'Chapter 2: Numbers'.ljust(line_width) + 'page 9'.rjust(line_width)
puts 'Chapter 3: Letters'.ljust(line_width) + 'page 13'.rjust(line_width)
end
counter = 10
while counter > 0
# Repeat what's in here as long as it's TRUE that the counter is greater than zero
puts "The counter is #{counter}"
counter = counter - 1
end
@jcasimir
jcasimir / estimating rails
Created April 18, 2011 23:36
Working on a formula to ballpark rails projects:
N = number of models
D = developer days/model = I'd approximate 3
C = complexity factor = 0.5 (ie, implementing 2 models is 3x as complex as one model)
M = number of views / model = 4 (on average)
E = developer days/view = I'd approximate 2 (given time for revisions, etc)
x = "Complexity" = C * (N ^ 2)
y = "Code" = D * N
z = "User Interface" = N * M * E
total = x + y + z
begin
beer = 3
while beer > 1
# Repeat what's in here as long as it's TRUE that the counter is greater than zero
puts "#{beer} bottles of beer on the wall, #{beer} bottles of beer! Take one down and pass it around,"
beer = beer - 1
if beer > 1
puts "#{beer} bottles of beer on the wall."
else
puts "#{beer} bottle of beer on the wall."
<h1><%= pluralize @articles.count, "Article" %></h1>
<%= link_to "Add", new_article_path, :class => "new_article" %>
<ul id="articles">
<% @articles.each do |article| %>
<li><%= link_to article.title, article_path(article) %></li>
<% end %>
</ul>
require "rubygems"
require "fastercsv"
class SalAttend
attr_accessor :file
attr_accessor :headers
# Added the parameter here...
def initialize(filename)
puts "JSAttend Initialized"
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :lookup, :only => [:show, :destroy, :edit, :update]
def lookup
class_name = params[:controller].singularize
klass = class_name.camelize.constantize
self.instance_variable_set "@" + class_name, klass.find(params[:id])
end
end
# Run this from the command line, not the console:
rails generate migration add_body_to_articles body:string
rake db:migrate
JSBlogger::Application.routes.draw do
resources :articles
resources :comments
match '/' => 'articles#index'
end