Skip to content

Instantly share code, notes, and snippets.

View elskwid's full-sized avatar
🤡

Don Morrison elskwid

🤡
View GitHub Profile
@elskwid
elskwid / connections.rb
Created February 3, 2014 16:41
Attribute DSL for mapping csv columns to Virtus attributes
# Straight Virtus
attribute :invoice_date, DateTime, default: :_invoice_date
attribute :invoice_number, String, default: :_invoice_number
attribute :invoice_amount, RowParser::Attributes::Money, default: :_invoice_amount
attribute :invoice_currency_code, String, default: :_invoice_currency_code
# Connections DSL
# multiple attribute connections
connect_attributes do
@elskwid
elskwid / log
Created February 21, 2014 07:02
Use a concern in a Controller
Started GET "/" for 127.0.0.1 at 2014-02-20 22:43:21 -0800
Processing by WebsiteController#index as HTML
Rendered text template (0.0ms)
Completed 200 OK in 2.3ms (Views: 1.9ms | ActiveRecord: 0.0ms)
some_method from shared logic
some_method from overridden in website controller

TravisCI Flowdock notifications for public repo and private flowdock rooms

notifications:
@elskwid
elskwid / object_allocation.rb
Last active August 29, 2015 14:05
Object allocation using literals vs. constants
require "benchmark"
require "gc_tracer"
include Process
class WithLiteral
def call
[]
end
end
@elskwid
elskwid / why_programming.md
Last active August 29, 2015 14:05
Why Programming?

An article I was asked to write for the UNR Extended Studies newletter in support of this class: Introduction to Programming

Why Programming?

Why programming? Why learn programming?

"They say that in Thailand there is a different Pad Thai recipe for every cook." — Alton Brown[1]

Like Pad Thai recipes, every programmer has their own answer to "why programming?" and that answer changes over time. I've always enjoyed solving problems. The rush that comes with the solution is hard to beat. The more challenging the problem, the bigger the reward. Take a gnarly issue, break it down, work it through, repeat for days, and then figure it out. Do you feel that? Cheer! Dance!

# Remember: use `ruby exercise3.rb` to run this file
# 1. display the contents of the `my_variable` variable
my_variable = "100"
# 2. assign the integer 5 to a variable named 'number'
# 3. display the contents of the 'number' variable
# 4. change (coerce) the string in 'my_variable' into an integer
@elskwid
elskwid / singleton_extend.rb
Created September 30, 2014 01:51
extended methods don't play nice
module A
def a_method
puts "a method"
end
end
# => :a_method
class B
extend A
def b_method
@elskwid
elskwid / exercise4.rb
Created October 1, 2014 00:22
exercise4
# Remember: use `ruby exercise4.rb` to run this file
# 1. display the contents of the `my_variable` variable
my_variable = "100"
# 2. assign the integer 5 to a variable named 'number'
# 3. display the contents of the 'number' variable
# 4. create an array with the values 1, 2, 4, and 5, assign it to a variable named `numbers`
@elskwid
elskwid / data.rb
Created October 1, 2014 03:30
wip data
# original data
# https://www.cisweb1.unr.edu/cxs/CourseListing.asp?master_id=1955&course_area=BASE&course_number=105&course_subtitle=00
data = File.read("data.txt")
lines = data.split("\n")
def extract_value_from_line(line, delimiter = ":")
line.split(delimiter)[1].to_s.strip
end
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowGroupToSeeBucketListInTheConsole",
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
"Effect": "Allow",