Skip to content

Instantly share code, notes, and snippets.

@peterxjang
peterxjang / gist:d13df97929bdc83071fe
Last active December 29, 2015 21:09
eslint rules
"rules": {
"indent": [2, 2],
"linebreak-style": [2, "unix"],
"semi": [2, "always"],
"eqeqeq": [2, "smart"],
"camelcase": 2,
"curly": 2,
"brace-style": [2, "1tbs"],
"space-before-function-paren": [2, "never"],
"array-bracket-spacing": [2, "never"],
# 1. Represent an employee as an array
employee1 = ["Majora", "Carter", 80000, true]
employee2 = ["Danilo", "Campos", 70000, true]
puts employee1[0] + " " + employee1[1] + " makes " + employee1[2].to_s + " a year."
puts "#{employee2[0]} #{employee2[1]} makes #{employee2[2]} a year."
# 2. Represent an employee as a hash
employee1 = {"first_name" => "Majora", "last_name" => "Carter", "salary" => 80000, "active" => true}
employee2 = {"first_name" => "Danilo", "last_name" => "Campos", "salary" => 70000, "active" => true}
puts "#{employee1['first_name']} #{employee1['last_name']} makes #{employee1['salary']} a year."
@data = {"query"=>{"count"=>1, "created"=>"2016-04-03T15:59:05Z", "lang"=>"en-US", "results"=>{"channel"=>{"units"=>{"distance"=>"mi", "pressure"=>"in", "speed"=>"mph", "temperature"=>"F"}, "title"=>"Yahoo! Weather - Nome, AK, US", "link"=>"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2460286/", "description"=>"Yahoo! Weather for Nome, AK, US", "language"=>"en-us", "lastBuildDate"=>"Sun, 03 Apr 2016 07:59 AM AKDT", "ttl"=>"60", "location"=>{"city"=>"Nome", "country"=>"United States", "region"=>" AK"}, "wind"=>{"chill"=>"14", "direction"=>"248", "speed"=>"11"}, "atmosphere"=>{"humidity"=>"80", "pressure"=>"1005.0", "rising"=>"0", "visibility"=>"16.1"}, "astronomy"=>{"sunrise"=>"8:8 am", "sunset"=>"10:3 pm"}, "image"=>{"title"=>"Yahoo! Weather", "width"=>"142", "height"=>"18", "link"=>"http://weather.yahoo.com", "url"=>"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"}, "item"=>{"title"=>"Conditions for Nome, AK, US at 06:00 AM AKDT", "la
@peterxjang
peterxjang / index.json.jbuilder
Last active April 5, 2016 01:19
jbuilder partial
json.array! @employees.each do |employee|
json.partial! 'employee.json.jbuilder', employee: employee
end
Rails.application.routes.draw do
namespace :v1 do
get '/employees' => 'employees#index'
get '/employees/:id' => 'employees#show'
post '/employees' => 'employees#create'
patch '/employees/:id' => 'employees#update'
delete '/employees/:id' => 'employees#destroy'
end
namespace :v2 do
Rails.application.routes.draw do
namespace :api do
namespace :v1 do
get '/employees' => 'employees#index'
get '/employees/:id' => 'employees#show'
post '/employees' => 'employees#create'
patch '/employees/:id' => 'employees#update'
delete '/employees/:id' => 'employees#destroy'
end
# app/controllers/api/v1/employees_controller.rb
class Api::V1::EmployeesController < ApplicationController
def index
@employees = Employee.all
end
#...
end
# app/controllers/v1/employees_controller.rb
class V1::EmployeesController < ApplicationController
def index
@employees = Employee.all
end
#...
end
def hello
puts 'yo'
end
def hello
puts 'yo'
end