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
Mediator = { | |
events: {} | |
listeners: {} | |
fireEvent: (type,event)-> | |
if @listeners[type] | |
@listeners[type].apply @, event | |
addListener: (type,callback) -> | |
@listeners[type] = callback | |
removeListener: (type) -> | |
delete @listeners[type] |
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 "net/http" | |
require 'cgi' | |
class Hash | |
# Create a Query String from a Hash | |
def to_query | |
def to_query | |
map { |k,v| | |
::CGI.escape(k.to_s)+"="+::CGI.escape(v) | |
}.join("&") |
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
module Faye | |
class ClientMiddleware | |
def initialize(app) | |
@app = app | |
end | |
def get_client | |
@fc ||= Faye::Client.new('http://localhost:3000/faye') | |
end | |
def call(env) | |
env['faye.client'] = get_client |
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
/** | |
* The first commented line is your dabblet’s title | |
*/ | |
.wrapper { | |
position: absolute; | |
top: 0; | |
left: 0; | |
bottom: 0; | |
right: 0; |
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
# This will not match and empty string. | |
register_variable_type(:required, /.+/) | |
# Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit. | |
register_variable_type(:password, /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$/) | |
register_variable_type(:email, /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/) |
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
new class Highlighter | |
entities: (s) -> | |
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"') | |
highlight: (code,lang) -> | |
map = code | |
tokens = {} | |
uid = 0 | |
for a in lang | |
code.replace a.regexp, (str) -> | |
map = map.replace str, "§"+uid |
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
window.addEvent "domready", -> | |
scroll = new Fx.Scroll($("content")) | |
$$("a[href^=#]").addEvent 'click', (e)-> | |
e.stop() | |
el = $$("a[name=#{@get('href')[1..]}]")[0] | |
scroll.toElement(el).chain -> window.location.hash = "#"+name |
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
a = new Class | |
Alias: | |
log: ['warn','error'] | |
log: (msg) -> | |
console.log msg | |
a.log "hello" | |
# prints hello | |
a.warn "warning" | |
# prints warning |
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
S3Bucket = "something" | |
def urlForS3(path) | |
if ENV['DATABASE_URL'] | |
"http://"+S3Bucket+".s3.amazonaws.com"+path | |
else | |
"/local/"+path | |
end | |
end |
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
current += (current+1 > length)?-length:1 |