Skip to content

Instantly share code, notes, and snippets.

Mediator = {
events: {}
listeners: {}
fireEvent: (type,event)->
if @listeners[type]
@listeners[type].apply @, event
addListener: (type,callback) ->
@listeners[type] = callback
removeListener: (type) ->
delete @listeners[type]
@gdotdesign
gdotdesign / config.ru
Created March 25, 2012 19:50
INK API Implementation
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("&")
@gdotdesign
gdotdesign / ClientMiddleware.rb
Created February 27, 2012 16:14
Faye Client Middleware for rack
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
@gdotdesign
gdotdesign / dabblet.css
Created February 17, 2012 09:39
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
.wrapper {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
@gdotdesign
gdotdesign / gist:1334062
Created November 2, 2011 16:13
Variable Types for renee
# 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}$/)
# Email
register_variable_type(:email, /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/)
@gdotdesign
gdotdesign / gist:1248030
Created September 28, 2011 14:09
Minimal Syntax Highlighter
new class Highlighter
entities: (s) ->
s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
highlight: (code,lang) ->
map = code
tokens = {}
uid = 0
for a in lang
code.replace a.regexp, (str) ->
map = map.replace str, "§"+uid
@gdotdesign
gdotdesign / gist:1177864
Created August 29, 2011 06:10
SmoothScroll alternate version #MooTools
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
a = new Class
Alias:
log: ['warn','error']
log: (msg) ->
console.log msg
a.log "hello"
# prints hello
a.warn "warning"
# prints warning
S3Bucket = "something"
def urlForS3(path)
if ENV['DATABASE_URL']
"http://"+S3Bucket+".s3.amazonaws.com"+path
else
"/local/"+path
end
end
@gdotdesign
gdotdesign / gist:985524
Created May 22, 2011 14:28
How to reset a counter in just one line
current += (current+1 > length)?-length:1