Skip to content

Instantly share code, notes, and snippets.

@mayfer
mayfer / hello_world.js
Created July 6, 2015 18:34
Intro to Node!
// run this with "node hello_world.js"
console.log("Hello World", __dirname);
@mayfer
mayfer / bubble.html
Created July 1, 2015 18:28
Javascript, jQuery, Ajax examples
<!-- demonstrating event bubbling -->
<html>
<head>
<title>arceegee</title>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<style>
body { margin: 0; }
#bubble { background: #ffa; width: 200px; height: 200px; }
# no *, / or % allowed
def divide(number, divisor)
result = 0
while number >= divisor
number -= divisor
result += 1
class CreateTeachers < ActiveRecord::Migration
def change
create_table :teachers do |t|
t.string :name
end
end
end
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:host => 'localhost',
:username => 'murat',
:password => '',
:database => 'lighthouse_2015_05',
require 'pg'
CONN = PG::Connection.new({
host: 'localhost',
user: 'murat',
password: '',
dbname: 'lighthouse_2015_05'
})
@mayfer
mayfer / arrays.rb
Created April 30, 2015 18:46
Arrays, Hashes, Blocks, Require
var = "asdhasd"
numbers = [
[1, 2, 3],
[4, 5, 6],
]
# WRONG
html, body {
}
.error {
background: #faa;
color: #a00;
}
.container {
@mayfer
mayfer / sesson.rb
Created April 23, 2015 18:38
Mock implementation of sessions
class Session
def [](key)
cookie = request.cookies["rack.session"]
output = decrypt(cookie)
return output["user_id"]
end
@mayfer
mayfer / actions.rb
Created April 23, 2015 18:34
Sinatra login/logout
# 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