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
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
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 '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
<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 '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
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
# find angle between clock hands | |
def angle(hour, minutes) | |
hour += (minutes / 60.0) | |
angle_hour = hour * 30 | |
angle_mins = minutes * 6 | |
(angle_hour - angle_mins).abs |
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
<!doctype html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="/style.css" /> | |
</head> | |
<body> | |
<% if @loggedin == true %> | |
welcome, <%=@username %> | |
<a href='/logout'>Log out</a> |
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
<!doctype> | |
<html> | |
<head> | |
<title>hi</title> | |
<style> | |
body, html { | |
background: #aaa; | |
font-family: monospace; |