Skip to content

Instantly share code, notes, and snippets.

@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()
@mattlenz
mattlenz / gist:1931659
Created February 28, 2012 09:56
Recursively download a website
wget -r -k -p http://example.com/
@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:2516984
Created April 28, 2012 07:55
Data URI for a 1px transparent GIF
data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
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 / 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
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 / Gemfile
Last active October 7, 2015 10:07
Tiny static-site Rack server
source :rubygems
gem 'rack'
@mattlenz
mattlenz / markdown_handler.rb
Created July 27, 2012 01:03
Rails Markdown (Kramdown) Template Handler
# config/initializers/markdown_handler.rb
module MarkdownHandler
def self.erb
@erb ||= ActionView::Template.registered_template_handler(:erb)
end
def self.call(template)
compiled_source = erb.call(template)
"Kramdown::Document.new(begin;#{compiled_source};end, auto_ids: false).to_html"
@mattlenz
mattlenz / gist:3280970
Created August 7, 2012 03:05
Test send HTML email
mutt -e 'set content_type="text/html"' you@example.com -s "HTML Email Test" < message.html