Skip to content

Instantly share code, notes, and snippets.

View fermion's full-sized avatar
👋

Rob Sterner fermion

👋
View GitHub Profile
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
@fermion
fermion / jquery.ba-detach.js
Created May 19, 2011 13:46 — forked from cowboy/jquery.ba-detach.js
jQuery Detach+: Improve .detach to allow optional reattaching!
/*!
* jQuery Detach+ - v0.1pre - 5/18/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
Rails CMS alternatives
======================
Note: project activity was checked on 11/26/09 for most of these projects, and the "last update" field has not been kept up to date since then.
Active projects:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
@fermion
fermion / gist:774390
Created January 11, 2011 13:11 — forked from remy/gist:350433
if (!window.localStorage || !window.sessionStorage) (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// Code
Function.prototype.curry = function() {
var func = this, a = Array.prototype.slice.call(arguments, 0);
return function() {
var a_len = a.length, length = arguments.length;
while (length--) a[a_len + length] = arguments[length];
return func.apply(this, a);
}
};
// See comments below.
// This code sample and justification brought to you by
// Isaac Z. Schlueter, aka isaacs
// standard style
var a = "ape",
b = "bat",
c = "cat",
d = "dog",
var NoiseEeeCalendarDateSelect = Class.create(CalendarDateSelect, {
initialize: function($super, target_element, options) {
// something to observe for a custom event on `this`
$super(target_element, options);
}
});
var dateSelect = new NoiseEeeCalendarDateSelect();
function select_towns(towns_string) {
var towns_arr = towns_string.split(','),
options = $$('#search_town_data option');
towns_arr.each(function(town_id_string) {
options.select(function(opt) {
return opt.value.match(town_id_string);
}).invoke('writeAttribute','selected',true);
});
}
new Effect.Parallel([
new Effect.BlindDown(area, {scaleFrom: 100, scaleTo: new_area_height_percentage }),
new Effect.Fade(element, { sync: true }),
new Effect.Appear(area.getElementsBySelector('.editor').first(), { sync: true,
afterSetup: function(effect) {
console.log(effect.element);
}
})
], { ..... }
});