Skip to content

Instantly share code, notes, and snippets.

View fanktom's full-sized avatar

Thomas Fankhauser fanktom

View GitHub Profile
@fanktom
fanktom / gist:1675562
Created January 25, 2012 09:11
Rails 3 CRUD Curls
# list
curl -v http://localhost:3000/organizations.json
# create
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"organization":{"first_name":"firstname","last_name":"lastname","email":"email@email.com"}}' http://localhost:3000/organizations
# read
url -v http://localhost:3000/organizations/1.json
# update
@fanktom
fanktom / server_side_events.rb
Created May 24, 2012 11:29
Ruby Server Side Events Server implementation with Goliath
require 'goliath'
require 'em-synchrony/em-http'
# After a connect the server streams 10 bomb ticks and then stops with a BOOM. The
# event source needs to listen to source.addEventListener 'bomb', .. to retrieve
# the ticks.
class Stream < Goliath::API
def response(env)
@fanktom
fanktom / randomize.sql
Created June 21, 2012 19:46
Social Database Simulation
/* Create Database */
DROP SCHEMA IF EXISTS `limits`;
CREATE SCHEMA `limits`;
USE `limits`;
/* Create Tables */
DROP TABLE IF EXISTS `limits`.`users`;
DROP TABLE IF EXISTS `limits`.`friends`;
DROP TABLE IF EXISTS `limits`.`statuses`;
@fanktom
fanktom / timeout.rb
Created August 7, 2012 09:03
Goliath API with_api call succeeding although it shouldn't
require 'goliath'
require 'eventmachine'
require 'em-synchrony'
require 'em-synchrony/em-hiredis'
class Server < Goliath::API
def response(env)
@redis = EM::Hiredis.connect
@redis.brpop "waiting_for_ever", 0
@fanktom
fanktom / gist:3763637
Created September 21, 2012 20:13
Normal Rails Controller
class TracksController < ApplicationController
# GET /tracks
def index
@tracks = Track.all
render "index"
end
# GET /tracks/1
def show
@fanktom
fanktom / gist:3763651
Created September 21, 2012 20:15
Scaled Rails Controller
class TracksController < ApplicationController
# GET /tracks
def index
@tracks = Track.all
Scales.push :html => render("index"), :to => "/tracks"
end
# GET /tracks/1
def show
@fanktom
fanktom / gist:3763687
Created September 21, 2012 20:21
ScaleUp File
require 'scales/up/rails'
desc "Scale up the cache"
Scales::Up.new do |scales|
# Stylesheets
scales.push :css, :to => "/assets/application.css?body=1"
scales.push :css, :to => "/assets/scaffolds.css?body=1"
scales.push :css, :to => "/assets/tracks.css?body=1"
@fanktom
fanktom / gist:3772781
Created September 23, 2012 19:39
Scales API Push
@html = "<html><head></head><body><p>Hello World</p></body></html>"
@xml = "<tracks><track><name>Islandary</name><artist>Thomas Fankhauser</artist></track></tracks>"
@json = '[{ name : "Islandary", artist : "Thomas Fankhauser" }]'
# Push a HTML
Scales.push :html => @html, :to => "/hello"
# Push a XML
Scales.push :xml => @xml, :to => "/hello.xml"
@fanktom
fanktom / gist:3772800
Created September 23, 2012 19:46
Scales API Update
# HTML Update URLs
Scales.update "/", "/tracks", "/overview", :format => :html
# XML Update URLs
Scales.update "/tracks.xml", "/overview.xml", :format => :xml
# JSON Update URLs
Scales.update "/tracks.json", "/overview.json", :format => :json
@fanktom
fanktom / gist:3772857
Created September 23, 2012 19:58
Scales API Modify
@html = '
<html>
<body>
<div><h1>Tracks</h1></div>
<div id="tracks">
<p id="track1">Track 1</p>
</div>
</body>
</html>'