This file contains 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' | |
require 'sinatra-websocket' | |
require 'tilt/erubis' | |
set :server, 'thin' | |
set :sockets, [] | |
get '/' do | |
if !request.websocket? | |
erb :index |
This file contains 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/base' | |
class MyApp < Sinatra::Base | |
@@my_app = {} | |
def self.new(*) self < MyApp ? super : Rack::URLMap.new(@@my_app) end | |
def self.map(url) @@my_app[url] = self end | |
class FooController < MyApp | |
map '/foo' |
This file contains 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 Profile | |
include Mongoid::Document | |
# .... | |
belongs_to :user | |
key :user_id | |
alias :to_s :_id | |
has_and_belongs_to_many :following, :class_name => 'Profile', :inverse_of => :followers | |
has_and_belongs_to_many :followers, :class_name => 'Profile', :inverse_of => :following | |
# .... |
This file contains 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
rails g migration Something attachable:polymorphic | |
or | |
rails g scaffold Something attachable:polymorphic | |
may can generate migration like this: | |
def self.up | |
create_table :somethings do |t| | |
t.references attachable, polymorphic => true |
This file contains 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
*filter | |
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0 | |
-A INPUT -i lo -j ACCEPT | |
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT | |
# Accepts all established inbound connections | |
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT |