Skip to content

Instantly share code, notes, and snippets.

View iamsok's full-sized avatar

David Sok iamsok

  • Acorio
  • Boston, MA
View GitHub Profile
@iamsok
iamsok / exercise.rb
Created September 4, 2014 22:03
exercise overview
# exercise is a hash
exercise = { name: 'jog', category: 'cardio', duration: 10 }
exercise.[](:name) # .[]() is a method we can call on only hashes
# exercise is an Exercise object
exercise = Exercise.new(exercise)
# exercise[:name] CAN'T DO THIS! exercise is not a hash anymore, so we can't call hash methods on it
# instead, we need to use the attr_reader methods to get attributes of the exercise
exercise.name # .name is a method we can call only on Exercise objects
@iamsok
iamsok / object card challenge
Last active August 29, 2015 14:05
Quick Challenge Card
##############################################################
#############################CARDS############################
##############################################################
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
1. SELECT movies.title, movies.rating FROM movies ORDER BY movies.rating LIMIT 50;
2. SELECT movies.title, movies.rating FROM movies WHERE movies.rating is NULL;
3. SELECT movies.title FROM movies WHERE movies.synopsis LIKE '%thrilling%’;
4. SELECT movies.title, movies.year, movies.rating
FROM movies JOIN genres ON genres.id = movies.genre_id WHERE movies.year BETWEEN 1980 AND 1989 AND genres.name = 'Science Fiction & Fantasy'
ORDER BY rating DESC;
@iamsok
iamsok / list_statistics.rb
Created August 16, 2014 21:58
Systems Check
scores = [75, 100, 85, 65, 84, 87, 95]
def avg(array)
total = 0
array.each do |grade|
total += grade
end
avg = total / array.length
avg
end
@iamsok
iamsok / favorite_movies.rb
Created August 14, 2014 21:21
favorite movies
favorite_movies = [
{ title: 'The Big Lebowski', year_released: 1998, director: 'Joel Coen', imdb_rating: 8.2 },
{ title: 'The Shining', year_released: 1980, director: 'Stanley Kubrick', imdb_rating: 8.5 },
{ title: 'Troll 2', year_released: 1990, directory: 'Claudio Fragasso', imdb_rating: 2.5 }
]
favorite_movies.each do |movies|
puts "#{movies[:year_released]}: #{movies[:title]}"
end
def average(grades)
grades.map! {|num| num.to_i}
grades.inject(0) {|sum, n| sum += n} / grades.size
end
puts 'Enter grades (one per line, type "done" on a new line when finished):'
grades = Array.new
grade = gets.chomp
while grade.downcase != "done"
grades << grade
➜ ~ cat ~/.zshrc
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"