Skip to content

Instantly share code, notes, and snippets.

@mayfer
mayfer / arrays.rb
Created April 30, 2015 18:46
Arrays, Hashes, Blocks, Require
var = "asdhasd"
numbers = [
[1, 2, 3],
[4, 5, 6],
]
# WRONG
require 'pg'
CONN = PG::Connection.new({
host: 'localhost',
user: 'murat',
password: '',
dbname: 'lighthouse_2015_05'
})
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:host => 'localhost',
:username => 'murat',
:password => '',
:database => 'lighthouse_2015_05',
class CreateTeachers < ActiveRecord::Migration
def change
create_table :teachers do |t|
t.string :name
end
end
end
# no *, / or % allowed
def divide(number, divisor)
result = 0
while number >= divisor
number -= divisor
result += 1
@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; }
@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 / anagram.rb
Created July 10, 2015 18:12
Algorithms & Data structures
def find_most_anagram
words = File.open('/usr/share/dict/words').read
hash = Hash.new { [] }
words.each_line do |word|
word = word.strip.downcase
signature = word.split('').sort.join('')
@mayfer
mayfer / server.rb
Created July 13, 2015 17:58
Intro to HTTP
require 'sinatra'
get '/' do
# whatever happens here happens on every request
puts "goodbye world"
response = "hello #{params[:username]} \n\n \
@mayfer
mayfer / caching.ejs
Created July 15, 2015 17:32
Caching
<!doctype html>
<html>
<head>
<title>weather</title>
<style>
body, html {
background: #05a;
color: #fff;
font-family: monospace;