Skip to content

Instantly share code, notes, and snippets.

@airy
airy / echo.rb
Created December 2, 2015 21:58
simple ws echo server
require 'sinatra'
require 'sinatra-websocket'
require 'tilt/erubis'
set :server, 'thin'
set :sockets, []
get '/' do
if !request.websocket?
erb :index
@airy
airy / my_app.rb
Created May 6, 2014 15:59 — forked from rkh/my_app.rb
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'
@airy
airy / profile.rb
Created May 12, 2011 22:31
Mongoid HATBM with string keys
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
# ....
@airy
airy / gist:659334
Created November 2, 2010 06:45
polymorphic migration
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
*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