Skip to content

Instantly share code, notes, and snippets.

Dan Webb danwrong

Block or report user

Report or block danwrong

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danwrong
danwrong / gist:71517
Created Feb 27, 2009
Idea of what DOM builder for jQuery should look like
View gist:71517
$.build(function(html) {
html.div(
html.a({ href: 'http://google.com' }, 'Click this link'),
html.span('Some text')
)
}).appendTo(body);
$.build(function(html) {
return html.div(
html.a({ href: 'http://google.com' }, 'Click this link'),
View gist:72734
// DOM Builder plugin idea for jQuery
//
// Usage:
// $.build(function(html) {
// html.div({ id: 'test' }, html.strong('Some text'));
// }); => DOM fragment
//
(function($) {
flatten = function(arr) {
View gist:107773
class Datafile
class << self
def glob(val)
@@globs ||= []
@@globs << [glob, self]
end
def find(path)
View gist:123613
state :new, :default => true do
handle :queue! do
enqueue
transition_to :queued
save!
end
handle :fetch_ga_data! do
fetch_ga_data
extract_terms
View gist:152882
require 'rubygems'
require 'hpricot'
require 'open-uri'
playlist = open('http://www.soundboard.com/playlist/REpFbW1hMjAwODQyMTQw_FjHigNpCqbI.xml')
doc = Hpricot::XML(playlist.read)
doc.search('//location').each do |node|
`curl -O #{node.inner_text}`
end
View gist:175591
$.fn.serializeHash = function() {
var arr = this.serialize();
var hash = {};
$.each(arr.split('&'), function(i, pair) {
var items = pair.split('=');
var key = unescape(items[0]), value = unescape(item[1]);
hash[key] = value;
});
View gist:198192
jQuery(function($) {
var SERVICES = {
'twitpic.com': function(path) {
var code = path.match(/\/([a-zA-Z0-9]+)/)[1];
return "http://twitpic.com/show/thumb/" + code;
}
};
var expression = $.keys(SERVICES).join('|');
View gist:199146
jQuery(function($) {
if (typeof $.keys != 'function') {
$.extend({
keys: function(obj) {
var a = [];
$.each(obj, function(k){ a.push(k) });
return a;
}
});
}
View ejs.jquery.js
// ERB style templates for jQuery in hardly any code.
//
// Based on http://ejohn.org/blog/javascript-micro-templating/
//
// A tiny and simple plugin to allow erb style template rendering within jQuery.
//
// Make a template:
//
// <script type="text/html" id="template1">
// <% $.each(items, function(i, image) { %>
View validation_reflection.rb
def mandatory?(method)
if @object.class.respond_to? :reflect_on_validations_for
@object.class.reflect_on_validations_for(method).any? { |val| val.macro == :validates_presence_of }
end
end
You can’t perform that action at this time.