Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / background.styl
Created September 28, 2011 00:12
gradient background (stylus)
body
background-image linear-gradient(top, sky, 80% sky, sky*0.7)
background-attachment fixed
///////////////////////////////////////////////////////////////
// from https://github.com/visionmedia/nib/blob/master/lib/nib/gradients.styl
linear-gradient(start, stops...)
error('color stops required') unless length(stops)
prop = current-property[0]
@mahemoff
mahemoff / app.js
Created September 29, 2011 14:54
Node wrapper for CoffeeScript (can use in Heroku)
var coffee = require('coffee-script'),
cs = require('fs').readFileSync('./app.coffee', 'ascii');
eval(coffee.compile(cs));
@mahemoff
mahemoff / example.coffee
Created October 7, 2011 12:58
Basic Support for CoffeeScript JSONP calls
importScripts 'jsonp-worker.coffee'
jsonp 'http://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=ev&callback=?', (response) ->
# process response
# adapted from http://dekstop.de/weblog/2006/02/recursive_ruby_opml_parser/
# Returns a map from URL => text-field
require 'rexml/Document'
def parse_opml(opml)
if opml.is_a? String
doc = REXML::Document.new(opml)
opml = doc.elements['opml/body']
end
feeds = {}
@mahemoff
mahemoff / Post.rb
Created November 1, 2011 11:20
Slug/Permalink using Rails 3 Concern
# example (untested)
class Post
include Slugged
end
post.create :title=>'Great Gist'
post.slug == 'great-gist' # true
@mahemoff
mahemoff / application_helper.rb
Created November 10, 2011 01:08
Rails 3+ Display Flashes, with option to choose if HTML is escaped or not
# extends http://snippets.dzone.com/posts/show/2348
# to include an option for escaping control
# flash[:success] = 'it worked!' will escape (safe) as per Rails 3 security measure, which
# defaults content_tag escaping to true
# flash[:explicit_success] = 'it <b>worked</b>!' will
module ApplicationHelper
FLASH_TYPES = [:error, :warning, :success, :notice]
@mahemoff
mahemoff / LICENSE.txt
Created November 19, 2011 01:28 — forked from sebastien-p/LICENSE.txt
base62 encode
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Sebastien P. https://twitter.com/#!/_sebastienp
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@mahemoff
mahemoff / gist:1402507
Created November 28, 2011 23:02
control freak script: linkify text file (quick hack)
var re = /http:\/\/\S+/g;
var s = document.body.innerHTML;
var m;
do {
m = re.exec(s);
if (m) {
console.log(m[0]);
document.body.innerHTML += '<li> <a href="'+m[0]+'">'+m[0]+'</a>';
}
@mahemoff
mahemoff / isLocal.coffee
Created December 2, 2011 22:54
check if URL is local (no scheme identifier)
isLocal = (url) -> ! /^[a-zA-Z0-9+-\.]+:/.test(url)
@mahemoff
mahemoff / check.haml
Created December 17, 2011 22:57
check if local variable is true/false in rails template (even if undefined)
/default is "true". this will also work with default "false"(by changing "true" below to "false").
- if ( local_assigns.has_key?(:show_message) ? show_message : true )