Skip to content

Instantly share code, notes, and snippets.

@mayfer
mayfer / input.rb
Created July 9, 2014 00:20
User input example
puts "Enter A"
a = gets.chomp
puts "Enter B"
b = gets.chomp
c = Integer(a) + Integer(b)
puts c
@mayfer
mayfer / rent.rb
Created July 9, 2014 00:20
Rent testing example
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
if baller && furnished || rent < 2100
return true
else
return false
end
end
@mayfer
mayfer / sound.js
Created July 11, 2014 00:32
Basic audio generation
// Built from Mohit Cheppudira's sine wave generator - http://0xfe.blogspot.com
// Modified by Murat Ayfer - http://muratayfer.com
soundWave = function(context) {
// xs is a list of x (time) values, one per wave.
// time is not represented as synchronized clicks or milliseconds, its passing is freq dependent
// so that's why we keep a value per each wave.
this.xs = [];
this.counter = 0;
this.context = context;
@mayfer
mayfer / orm.rb
Created July 23, 2014 00:42
ORM breakout
class ORM
def save
table_name = self.class
sql_columns = self.instance_variables.map do |i|
i.slice(1, i.length)
end.join(', ')
sql_values = self.instance_variables.map do |i|
'"' << self.instance_variable_get("#{i}") << '"'
@mayfer
mayfer / url_heplers.rb
Created August 9, 2014 02:03
Rails URL Helpers proof of concept
class MuratsController
def initialize
end
def index
end
def beard
end
end
@mayfer
mayfer / activerecord.rb
Created August 9, 2014 02:04
ActiveRecord includes/join example
require 'active_record'
require 'pg'
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:host => 'ec2-54-204-41-178.compute-1.amazonaws.com',
:username => 'bmdjwluxchptuq',
:password => 'aEH-cKdr2zoXYUAjI8Xjma5eXK',
@mayfer
mayfer / rich.html
Created August 12, 2014 01:33
jQuery example demonstrating working with anonymous and named callbacks
<html>
<head>
<style>
body { background: #358; color: #fff; padding: 50px; font-family: sans-serif; }
</style>
<!-- we need to load jquery before we use it -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
@mayfer
mayfer / form_example.rb
Created August 22, 2014 17:16
A simple example demonstrating sending POST data from an HTML form
require 'sinatra'
get '/' do
<<-eos
<html>
<head>
<title>coffee orbit</title>
</head>
<body>
@mayfer
mayfer / math.rb
Created September 7, 2014 00:53
veronika's math game
#future update: count time, after 1 min, swith the user - 1 life
# Assignment created as a new Github repository
# require pry
# binbinding.pry
@players = [{
life: 3,
score: 0,
level: 1,
name: "Player 1"
@mayfer
mayfer / ajax.rb
Created September 10, 2014 18:37
jQuery/AJAX/JSON/sinatra example
require 'sinatra'
require 'nokogiri'
require 'open-uri'
require 'sinatra/json'
# require 'json'
# sets the view directory correctly (to make it work with gists)
set :views, Proc.new { File.dirname(__FILE__) }