This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
attr_accessor(:name, :email) | |
# class variable | |
@@emails = [] | |
@@population = 0 | |
def initialize(name, email) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/json' | |
def get_click_data | |
{ | |
count: Click.count, | |
last_timestamp: Click.all.order('created_at DESC').first.created_at | |
} | |
end | |
get '/' do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Intro to Javascript</title> | |
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<style> | |
body { background: #358; color: #fff; padding: 50px; font-family: sans-serif; } | |
.row { | |
background: rgba(255, 255, 255, 0.5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pg' | |
$conn = PG::Connection.open(:dbname => 'lighthouse') | |
class Venue | |
attr_accessor :name, :capacity, :id | |
def initialize(name, capacity) | |
@id = nil | |
@name = name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ORM | |
def save | |
if defined? @id | |
sql_update | |
else | |
sql_insert | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
post '/' do | |
response.set_cookie("username", params[:username]) | |
redirect '/' | |
end | |
get '/logout' do | |
response.set_cookie("username", value: "test", expires: Time.now ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_index(numbers, number) | |
numbers.each_with_index do |n, i| | |
if n == number | |
return i | |
end | |
end | |
return nil | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Homepage (Root path) | |
enable :sessions | |
helpers do | |
def current_user | |
begin | |
@current_user = User.find(session["user_id"].to_i) | |
# @current_user = User.find(response.cookies["user_id"].to_i) | |
rescue | |
@current_user = nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Session | |
def [](key) | |
cookie = request.cookies["rack.session"] | |
output = decrypt(cookie) | |
return output["user_id"] | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html, body { | |
} | |
.error { | |
background: #faa; | |
color: #a00; | |
} | |
.container { |