Skip to content

Instantly share code, notes, and snippets.

module TinyId
extend ActiveSupport::Concern
module ClassMethods
def base
Radix::BASE::B62
end
def find_by_tiny_id(string)
find(string.b(self.base.length).to_i)
@mattlenz
mattlenz / database.yml
Created July 9, 2012 03:02
Rails database config with inheritance
defaults: &defaults
adapter: postgresql
encoding: unicode
host: localhost
database: blog
development:
<<: *defaults
database: blog_development
set shell=bash\ -i
silent !defaults write org.vim.MacVim MMTextInsetTop 0
silent !defaults write org.vim.MacVim MMTextInsetRight 0
silent !defaults write org.vim.MacVim MMTextInsetBottom 0
silent !defaults write org.vim.MacVim MMTextInsetLeft 0
let mapleader=","
colorscheme Solarized
@mattlenz
mattlenz / gist:2516984
Created April 28, 2012 07:55
Data URI for a 1px transparent GIF
data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
@mattlenz
mattlenz / centreElement.js.coffee
Created March 1, 2012 01:02
Centre align and element relative to parent (or window)
$.fn.centre = (dims = ['left', 'top'], parent = window, offset = 0) ->
that = @
_.each dims, (dim) ->
prop = 'width' if dim == 'left'
prop = 'height' if dim == 'top'
parent_prop = eval("$(parent).#{prop}()")
this_prop = eval("$(that).#{prop}()")
@mattlenz
mattlenz / gist:1931659
Created February 28, 2012 09:56
Recursively download a website
wget -r -k -p http://example.com/
@mattlenz
mattlenz / jquery.placeholder.js.coffee
Created February 20, 2012 07:04
jQuery Placeholder Shim
$.fn.placeholder = ->
@data('placeholder', @attr('placeholder')).removeAttr('placeholder').attr('value', @data('placeholder'))
@on 'focus', ->
$(@).attr('value', '') if @value == $(@).data('placeholder')
.on 'blur', ->
$(@).attr('value', $(@).data('placeholder')) if @value.length == 0
jQuery -> $('[placeholder]').placeholder()