Skip to content

Instantly share code, notes, and snippets.

mwunsch / replicate.js
Created February 5, 2014 18:39
Clone DOM node w/ relevant styles
* HTMLElement.replicate()
* Here's an extension to the DOM's [HTMLElement interface][1] that completely
* replicates an element. Unlike `Node.cloneNode`, this method also copies over
* relevant styles. This allows you to clone nodes completely detached from the
* source document, but with enough information to render their independent
* representation.
require 'rumoji'
codepoints =
codepoints.each do |c|
puts "{c}.png"
mwunsch /
Last active August 29, 2015 14:06
Upload from shell to
puthtml ()
curl -F "file=@${1:--};filename=${1:-`uuidgen`.html}" \
-F "api_key=${2:-$PUTHTML_API_KEY}" \;
mwunsch / dress.html
Created April 23, 2015 21:04
createTreeWalker + createDocumentFragment = diff
<!DOCTYPE html>
<div class="grid-thumb" id="grid-thumb-viv9" data-style-name="VIV9">
<a class="item-link" href="/shop/designers/vivienne_westwood_anglomania/julia_dress">
<div class="grid-thumb-images">
<img class="current" alt="Vivienne%20Westwood%20Anglomania - Julia%20Dress" width="270" height="405" src="">
<img alt="Vivienne%20Westwood%20Anglomania - Julia%20Dress" width="270" height="405" src="" class="">
<img alt="Vivienne%20Westwood%20Anglomania - Julia%20Dress" width="270" height="405" src="">
mwunsch / dom-zipper.js
Last active August 29, 2015 14:19
A blah implementation of a Zipper for the DOM
/* I'm not thrilled with this, but it should be enough to demonstrate ... something ... */
function Breadcrumb(el) {
this.path = el.parentElement ? new Breadcrumb(el.parentElement) : null;
this.left = el.previousElementSibling;
this.right = el.nextElementSibling;
function Zipper(tree, path) {
this.tree = tree;
this.crumb = new Breadcrumb(tree);
# These two lines of code kind of do the same thing.
# They both add the directory of the file the Ruby interpreter
# is currently executing to the Load Path.
# Useful when no gem is installed.
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
$:.unshift File.dirname(__FILE__)
mwunsch / gist:109799
Created May 11, 2009 00:18
ActiveSupport's Nokogiri Parser. Like the to_hash method.
require 'nokogiri'
# = XmlMini Nokogiri implementation
module ActiveSupport
module XmlMini_Nokogiri #:nodoc:
extend self
# Parse an XML Document string into a simple hash using libxml / nokogiri.
# string::
# XML Document string to parse
mwunsch / gist:109809
Created May 11, 2009 00:37
Working to build a to_hash method for a Nokogiri::XML::Document
# Converting Nokogiri parsed XML to_hash
require 'nokogiri'
module Extensions
module Document
def to_hash
mwunsch / gist:110536
Created May 12, 2009 15:23
Weary DSL brainstorming
# DSL method ideas (for Weary)
class Twitter < Weary::Base
on_domain ''
as_format :json
declare_resource 'statuses/user_timeline',
:via => :get,
:with => [:id],
:forms_url => "#{domain}#{resource}.#{format}?#{query}"
mwunsch / activeresource_httpmock.rb
Created May 14, 2009 20:23
ActiveResource's HttpMock class
require 'active_resource/connection'
require 'active_support/core_ext/kernel/reporting'
module ActiveResource
class InvalidRequestError < StandardError; end #:nodoc:
# One thing that has always been a pain with remote web services is testing. The HttpMock
# class makes it easy to test your Active Resource models by creating a set of mock responses to specific
# requests.