Skip to content

Instantly share code, notes, and snippets.

@ogryzek
ogryzek / ruby_fee_struct.rb
Last active August 29, 2015 13:56
ruby Struct
Fee = Struct.new(:percentage, :max, :min)
# # equivalent to
# class Fee
# attr_accessor :percentage, :max, :min
# def initialize(percentage, max, min)
# self.percentage = percentage
# self.max = max
# self.min = min
# end
@ogryzek
ogryzek / homepage_controller_spec.rb
Last active August 29, 2015 13:56
rspec Homepage Features, Controller, Model examples
require 'spec_helper'
describe HomepageController do
describe "#index" do
it "is successful" do
get :index
expect(response).to be_success
end
end
@ogryzek
ogryzek / procs_and_lambdas.rb
Created February 26, 2014 05:27
Ruby Procs and Lambdas
# What's the difference between procs and lambdas?
#
# To really understand the difference, put it to use.
# irb is great for this.
# In irb, instantiate a Lambda and a Proc
l = lambda {|x, y| x.times {puts y}}
p = Proc.new {|x, y| x.times {puts y}}
# See that they are both of the same class
@ogryzek
ogryzek / _option_fields.html.haml
Last active August 29, 2015 13:56
accepts_nested_attributes
%fieldset.answer
= f.label :title
= f.text_field :title
= f.label :body
= f.text_field :body
= f.check_box :_destroy
= f.label :_destroy
%br
@ogryzek
ogryzek / intro_to_ruby.md
Last active August 29, 2015 13:57
Intro to Ruby

Intro to Ruby

IRB
Open up the terminal and in bash type

ruby -v

Open up an Interactive Ruby Shell

irb

#Data Structures

Arrays | Hashes

Arrays

In Ruby, we define an aray simply using square brackets []

a = [1, 59, "Hey", "Yo", 200]
a[2]                  # "Hey"

You can put anything inside an array

Classes & Objects

Before object oriented programming, there was what's called 'Procedural Programming'. If I wanted to describe the mundane takss of my day to day routine, I could do so using procedures, such as "I wake up. I brush my teeth, etc."

However, we as humans tend to think of everything as an object. This is why languages like Ruby take objects to the extreme by making everything objects. Object oriented programming is good, because it makes thing easier to understand, and easier to extend. I can just include a library and have access to many more objects and methods.

I get into a car, which is an object. I turn on the car, which is a method on the object. Object interacting with each other is what OOP is all about.

Most modern languages are object oriented. Php, Java, Scala, etc.

Some Differences between a Class and an Object

Settings for IRB colors

To get some nice colors in your irb, you can install the gems awesome_print and interactive_editor. There should be a dot file (hidden file) in your home directory called .irbrc, if not just create it: sublime ~/.irbrc.

gem install awesome_print
gem install interactive_editor
sublime ~/.irbrc

Tam's settings

@ogryzek
ogryzek / week1_html_and_css.md
Created March 20, 2014 16:20
Week 1: HTML & CSS with Jay

HTML & CSS

Create a static HTML site with 1 or more external CSS stylesheets linked to from a CSS subfolder. Your HTML files should contains all of the items listed below. It should be made up of a minimum of 4 pages. It does not need to be pretty in any way shape or form, but should be functional. You may not use any prefabricated assets or frameworks with the exception of "normalize.css" which is permitted. For images in your page use the placeholder service "http://placehold.it" For text on your page use "Lorem ipsum" text (http://littleipsum.com). For video on the site, use both a .webm video and an .mp4 video. You may use the files located at: http://codecore.ca/video.

HTML5 elements

<header> 
<nav>
<section>