Skip to content

Instantly share code, notes, and snippets.

@gdotdesign
gdotdesign / .rubocop.yml
Last active August 29, 2015 14:06
DiNa Rubocop Config
AllCops:
RunRailsCops: true
Style/AccessModifierIndentation:
EnforcedStyle: indent
Style/AlignHash:
Enabled: false
Style/AlignParameters:
@gdotdesign
gdotdesign / addedToDom.coffee
Created October 21, 2010 11:12
Mootools addedToDom event.
Element.NativeEvents['DOMNodeInsertedIntoDocument'] = 2
Element.Events['addedToDom'] = {
base: 'DOMNodeInsertedIntoDocument'
}
@gdotdesign
gdotdesign / Number.eval.coffee
Created April 2, 2011 10:08
Parses a string as a mathematical expression. Replaces percentages based on a number.
Number.eval = (string,size) ->
Number.from(eval(String.from(string).replace /(\d*)\%/g, (match,str) ->
(Number.from(str)/100)*size
))
class Cache2
def initialize(opts={})
options = {:expiration => 24*60*60}.merge!(opts)
@exp = options[:expiration]
end
def [](index)
if @cache[index].expired? then @cache[index].refresh end
@cache[index].contents
end
def add(index, expires=nil, &block)
@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
S3Bucket = "something"
def urlForS3(path)
if ENV['DATABASE_URL']
"http://"+S3Bucket+".s3.amazonaws.com"+path
else
"/local/"+path
end
end
a = new Class
Alias:
log: ['warn','error']
log: (msg) ->
console.log msg
a.log "hello"
# prints hello
a.warn "warning"
# prints warning
@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
@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: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/)