Skip to content

Instantly share code, notes, and snippets.

vis = d3.select("body").append("svg:svg").attr("class", "vis");
@nowherenearithaca
nowherenearithaca / gist:2852155
Created June 1, 2012 13:29
html generated from vis
<svg class="vis">
@nowherenearithaca
nowherenearithaca / gist:2852297
Created June 1, 2012 13:49
d3 "append" definition
d3_selectionPrototype.append = function(name) {
name = d3.ns.qualify(name);
function append() {
return this.appendChild(document.createElementNS(this.namespaceURI, name));
}
function appendNS() {
return this.appendChild(document.createElementNS(name.space, name.local));
}
{space: "http://www.w3.org/2000/svg", local: "svg"}
qualify: function(name) {
var i = name.indexOf(":"),
prefix = name;
if (i >= 0) {
prefix = name.substring(0, i);
name = name.substring(i + 1);
}
return d3_nsPrefix.hasOwnProperty(prefix)
? {space: d3_nsPrefix[prefix], local: name}
: name;
var d3_nsPrefix = {
svg: "http://www.w3.org/2000/svg",
xhtml: "http://www.w3.org/1999/xhtml",
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/"
};
@nowherenearithaca
nowherenearithaca / prependanimate.js
Last active December 11, 2015 10:38
Snippet for blog; this snippet is from Cletus' answer to this stack overflow post: http://stackoverflow.com/questions/3034752/jquery-appending-an-li-to-a-ul-and-then-animating-that-li
$("<li>This is my item</li>")
.hide()
.prependTo("#news-feed")
.slideDown();
@nowherenearithaca
nowherenearithaca / snippet.html
Last active December 11, 2015 23:59
Snippet for blog
<script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script>
<a href="https://twitter.com/intent/tweet?in_reply_to=51113028241989632">Reply</a>
<a href="https://twitter.com/intent/retweet?tweet_id=51113028241989632">Retweet</a>
<a href="https://twitter.com/intent/favorite?tweet_id=51113028241989632">Favorite</a>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.29.1"></script>
<style type="text/css">
html, body, #map {
width: 100%;
@nowherenearithaca
nowherenearithaca / MainViewController.m
Last active December 14, 2015 02:29
Snippet for handling external links in a PhoneGap app. I don't know the original source for this.
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}