This file contains hidden or 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
WORDS = %w[a an app apple pi pie bug] | |
class Applepie | |
def initialize(text) | |
@text = text | |
end | |
def words | |
words = [] | |
text = @text.dup |
This file contains hidden or 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
convertCurrency = (input) -> | |
value = $(input).val().replace /[^\d\.]/g, '' | |
float = parseFloat(value) | |
float = 0 if isNaN(float) | |
precision = parseInt(input.attr('data-precision')) | |
if precision is 0 | |
val = float.toString().replace /\.\d*/, '' | |
else | |
val = float.toString().replace new RegExp("(\\.\\d{#{precision}})\\d*"), '$1' | |
val = parseFloat val |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |