Skip to content

Instantly share code, notes, and snippets.

View DarrenN's full-sized avatar
🌵
(on-a vision-quest)

Darren DarrenN

🌵
(on-a vision-quest)
View GitHub Profile
@zzak
zzak / gist:830035
Created February 16, 2011 19:49
define_method hello, world!
def add_method(obj, mod, &blk)
obj.class_eval { define_method(mod, &blk) }
end
add_method(String, :greet) { "Hello, #{self}" }
"world".greet #=> "Hello, world!"
@chriseppstein
chriseppstein / pending_blog_posts.markdown
Created March 30, 2011 22:27
A list of blog posts that I should write.
  • Mini state machines for page state with sass/jquery and html or body classes.
  • double-layer color constants: layer one: color names ($olive-green), layer two: common uses of colors ($link-color).
@mads-hartmann
mads-hartmann / Coffeescript ctags
Created April 7, 2011 07:44
ctags definitions for Coffeescript. Very basic for now. "> ctags -e -R source_folder" and then M-. to jump to the definition of any function or variable (if you're using emacs)
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=.*->.*$/\1/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/

A pure CSS bendy shadow:

I suspect that some trig calculations could make this very general.

bendy_shadow

require 'sinatra/base'
class MyApp < Sinatra::Base
@@my_app = {}
def self.new(*) self < MyApp ? super : Rack::URLMap.new(@@my_app) end
def self.map(url) @@my_app[url] = self end
class FooController < MyApp
map '/foo'
#!/usr/bin/env ruby
require 'nokogiri'
path = ARGV.shift || File.join(ENV['HOME'], "Music/iTunes/iTunes Music Library.xml")
doc = Nokogiri.XML File.open(path)
tracks = []
doc.xpath('/plist/dict/dict/dict').each do |node|
children = node.children.map(&:text).reject { |x| x.strip.empty? }
@chriseppstein
chriseppstein / dry_inner_content_using_capture.haml
Created May 23, 2011 19:07
This gist shows some approaches for using haml without repeating inner content
- content_for(:inner_content) do
= render :partial => "inner_content"
- if some_condition
%outertag1= yield :inner_content
- else
%outertag2= yield :inner_content
@vivien
vivien / coderwall.rb
Created June 4, 2011 04:50
Simple and Stupid Ruby API for Coderwall.com
# Simple and Stupid Ruby API for Coderwall.com
# Vivien Didelot <[email protected]>
require "open-uri"
require "json"
module CoderWall
class Achievement
attr_reader :name, :badge, :description
@anhang
anhang / localStorage.js
Created July 20, 2011 23:07
HTML5 Local Storage with Expiration
AZHU.storage = {
save : function(key, jsonData, expirationMin){
if (!Modernizr.localstorage){return false;}
var expirationMS = expirationMin * 60 * 1000;
var record = {value: JSON.stringify(jsonData), timestamp: new Date().getTime() + expirationMS}
localStorage.setItem(key, JSON.stringify(record));
return jsonData;
},
load : function(key){
if (!Modernizr.localstorage){return false;}
@topfunky
topfunky / new-github.sh
Created July 25, 2011 22:23
Shell shortcut to setup a Git repo with GitHub. Works with zsh or bash.
# Usage: new-github topfunky tidy_table
function new-github() {
git remote add origin [email protected]:$1/$2.git
git push origin master
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git config push.default current
}