Skip to content

Instantly share code, notes, and snippets.

@sranso
sranso / FakeArray
Last active December 31, 2015 17:38
class FakeArray
attr_reader :info
def initialize
@info = ["puppies", "kittens", "baby sloths", "puppies"]
end
def each
@info.each do |element|
yield element if block_given?
(rdb:1) Dog.find_by_id(13)
#<Mysql2::Result:0x007fd2329a2c50 @query_options={:as=>:hash, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:local, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>2147525125, :cast=>true, :default_file=>nil, :default_group=>nil, :host=>"localhost", :username=>"root", :database=>"dogs"}>
(rdb:1) Dog.find_by_id(13).first
{"id"=>13, "name"=>"sara", "color"=>"red"}
...
def self.find_by_id(id)
results = self.db.query ("
SELECT *
FROM dogs
WHERE id = #{id}
")
end
...
/* descendant selector */
ul li {
color: purple;
}
/* child combinator selector */
ul > li {
text-transform: uppercase;
}
/* adjacent sibling combinator */
p + p {
# in config/routes.rb
RailsSampleApp::Application.routes.draw do
resources :posts
# SHORTCUT VERB ROUTE CONTROLLER#ACTION
# posts GET /posts(.:format) posts#index
# POST /posts(.:format) posts#create
# new_post GET /posts/new(.:format) posts#new
# edit_post GET /posts/:id/edit(.:format) posts#edit
# post GET /posts/:id(.:format) posts#show
# PUT /posts/:id(.:format) posts#update
class App < Sinatra::Application
get '/' do
@meal = Mealtime.new(Time.now)
erb :index
end
end
/* JavaScript example of loose typing */
var a = "twenty two"; // String delcaration
var b = 22; // Number declaration
/* ActiveRecord example of strong typing */
create_table do |t|
t.string name
t.integer age
end
var a = "sarah";
function dance_with_gus(some_var){
a = "gus";
return(some_var + " dances with " + a );
}
// "gus dances with gus"
var a = "sarah";
function dance_with_gus(some_var){
var a;
Perform these exercises in the JavaScript console of your favorite web browser.
What does the following expression return?
> 3 + 2;
5
=============================================================
What does the following expression return?
> typeof(3);