Skip to content

Instantly share code, notes, and snippets.

Avatar

Chet Corcos ccorcos

View GitHub Profile
@ccorcos
ccorcos / gist:9657939
Created Mar 20, 2014
A more complete but still incomplete Bounded Force Layout
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();
@ccorcos
ccorcos / gist:9657279
Created Mar 20, 2014
Why is the div larger than my inner svg element using D3?
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;
}
@ccorcos
ccorcos / gist:9677078
Last active Aug 29, 2015
Bootstrap 2 typeahead with Meteor
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;
@ccorcos
ccorcos / gist:10683090
Created Apr 14, 2014
simple python exception
View gist:10683090
class MyException(Exception):
def __init__(self, msg):
Exception.__init__(self, msg)
if True:
raise MyException("fucked up")
@ccorcos
ccorcos / gist:10774818
Created Apr 15, 2014
how to check for a python package version at runtime
View gist:10774818
import pkg_resources
def version(packageName):
return pkg_resources.get_distribution(packageName).version
package = "matplotlib"
print package + ": " + version(package)
@ccorcos
ccorcos / smallNumbers.py
Created Apr 15, 2014
How to take the sum of very small numbers, a + b + c + ..., when you only have log(a), log(b), log(c), and exp(log(a)) = 0.0 due to lack of precision. What we get in return is log(a + b + c + ...)
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)
@ccorcos
ccorcos / completely.js
Created Apr 21, 2014
complete.ly (js) customized for semantic-ui
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 || {};
@ccorcos
ccorcos / gist:11132188
Created Apr 21, 2014
how to use hotkeys.js
View gist:11132188
$('body').hotKey({
key: 's',
modifier: 'cmd'
}, saveNote)
$('body').hotKey({
key: 'esc',
}, cancelNote)
@ccorcos
ccorcos / okcancel.js
Created Apr 21, 2014
ok cancel events for meteor
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] =
You can’t perform that action at this time.