View gist:9657939
I found this: http://bl.ocks.org/mbostock/1129492 | |
But it doesn't work when you want the svg to be responsive to the browser window size: | |
svg = d3.select("#network").append("svg") | |
.attr("viewBox", "0 0 " + width + " " + height) | |
.attr("preserveAspectRatio", "xMidYMid meet"); | |
Since the height and width are the units of the svg now, we need to account for when the height and width aren't the same as when initialized. Note that for this example, height = width = 800. This example needs to be alters if height != width. | |
var currentWidth = $("svg").width(); |
View gist:9657279
http://stackoverflow.com/questions/4640348/why-do-scrollbars-appear-when-using-a-svg-element-inside-a-div/4642713#4642713 | |
svg { | |
display:block; | |
} |
View gist:9677078
I spent way too long trying to get this to work. | |
Template.search.events({ | |
'keyup input#search': function(e, t) { | |
if (e.keyCode == 13) { | |
// if the user presses enter to select a typeahead | |
var node = Nodes.findOne({ | |
title: e.target.value | |
}); |
View gist:9675658
I was having an issue that a function in another file wasn't seeing a variable in another file: | |
http://stackoverflow.com/questions/22545559/javascript-design-patterns-with-meteor/22546366 | |
file scope | |
var x = 10; | |
meteor global scope | |
x = 10; |
View gist:10683090
class MyException(Exception): | |
def __init__(self, msg): | |
Exception.__init__(self, msg) | |
if True: | |
raise MyException("fucked up") |
View gist:10774818
import pkg_resources | |
def version(packageName): | |
return pkg_resources.get_distribution(packageName).version | |
package = "matplotlib" | |
print package + ": " + version(package) |
View smallNumbers.py
from pylab import * | |
# Some Log rules: | |
# a*b = log(a) + log(b) | |
# a/b = log(a) - log(b) | |
# a**b = b*log(a) | |
# exp(log(x)) = log(exp(x)) = x | |
# | |
# The Trick: | |
# log(a + b) = log(a + b) - log(c) + log(c) |
View completely.js
/** | |
* complete.ly 1.0.0 | |
* MIT Licensing | |
* Copyright (c) 2013 Lorenzo Puccetti | |
* | |
* This Software shall be used for doing good things, not bad things. | |
* | |
**/ | |
completely = function completely(container, config) { | |
config = config || {}; |
View gist:11132188
$('body').hotKey({ | |
key: 's', | |
modifier: 'cmd' | |
}, saveNote) | |
$('body').hotKey({ | |
key: 'esc', | |
}, cancelNote) |
View okcancel.js
////////// Helpers for in-place editing ////////// | |
// Returns an event map that handles the "escape" and "return" keys and | |
// "blur" events on a text input (given by selector) and interprets them | |
// as "ok" or "cancel". | |
okCancelEvents = function(selector, callbacks) { | |
var ok = callbacks.ok || function() {}; | |
var cancel = callbacks.cancel || function() {}; | |
var events = {}; | |
events['keyup ' + selector + ', keydown ' + selector] = |
OlderNewer