Skip to content

Instantly share code, notes, and snippets.

@akcrono
akcrono / csv_parser.rb
Last active February 4, 2016 16:03
Useful script for quickly pulling data out of csv's into a ruby console.
require 'csv'
require 'pry'
require 'active_support/all'
class CSVParser
attr_accessor :filename, :items, :rows, :options, :headers
# Optional params:
# -nh No header in csv
def initialize(args)
class CustomMailExporter
require 'fileutils'
attr_accessor :service, :target_users, :target_start_date, :target_end_date,
:path, :errors, :filename_counter, :emails_found
# Dates should be in Date or DateTime format. Users should be an array.
def initialize(service, target_users, target_start_date, target_end_date)
@service = service
@target_users = target_users.map(&:downcase)
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase
@contents = []
end
class Car
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
end
def color
@color
end
class Card
def initialize(rank, suit)
@suit = suit
@rank = rank
end
def suit
@suit
end
class television
def initialize(make, model, type, channel = 3, volume = 5)
@make = make
@model = model
@type = type
@channel=channel
@volume=volume
end
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
if rank.nil?
srand()
@rank = rand(13)+1
SELECT title, rating FROM movies ORDER BY rating LIMIT 50;
SELECT title FROM movies WHERE rating = 0 ORDER BY title;
SELECT title FROM movies WHERE synopsis LIKE '%thrilling%';
SELECT movies.title, movies.year, movies.rating FROM movies JOIN genres ON movies.genre_id = genres.id WHERE genres.name = 'Science Fiction & Fantasy' AND year BETWEEN 1980 AND 1989 ORDER BY rating DESC;
SELECT actors.name, movies.title, movies.year FROM movies
JOIN cast_members ON movies.id = cast_members.movie_id
@akcrono
akcrono / systemscheck1.rb
Created August 18, 2014 01:09
first systems check for Launch Academy. 3 methods returning average, max, and min scores.
def find_average scores
sum = 0.0
scores.each do |x|
sum += x
end
return sum/scores.length
end
def find_max scores
answer = 0
@akcrono
akcrono / cash_register3.rb
Created August 14, 2014 17:50
csv cash register project for Launch Academy
require 'csv'
require 'pry'
def return_sku (hash, number)
answer = hash.first(number)
return answer[-1][0]
end