Skip to content

Instantly share code, notes, and snippets.

@tophtucker
tophtucker / excelmacros
Created March 5, 2014 17:57
Excel macros
Function HLink(rng As Range) As String
'extract URL from hyperlink
'posted by Rick Rothstein
If rng(1).Hyperlinks.Count Then HLink = rng.Hyperlinks(1).Address
End Function

Keybase proof

I hereby claim:

  • I am tophtucker on github.
  • I am tophtucker (https://keybase.io/tophtucker) on keybase.
  • I have a public key whose fingerprint is 38F8 35B0 0FC4 9A0D 6D74 733D B96E A5CF 4410 BBA5

To claim this, I am signing this object:

Page Highlighters Quotation
1 3312 When the rate of return on capital exceeds the rate of growth of output and income, as it did in the nineteenth century and seems quite likely to do again in the twenty-first, capitalism automatically generates arbitrary and unsustainable inequalities that radically undermine the meritocratic values on which democratic societies are based.
10 1807 Like his predecessors, Marx totally neglected the possibility of durable technological progress and steadily increasing productivity, which is a force that can to some extent serve as a counterweight to the process of accumulation and concentration of private capital.
15 1817 The sharp reduction in income inequality that we observe in almost all the rich countries between 1914 and 1945 was due above all to the world wars and the violent economic and political shocks they entailed (especially for people with large fortunes). It had little to do with the tranquil process of intersectoral mobility described by Kuznets.
19 1552 Inequal
@tophtucker
tophtucker / stateface-mapping.js
Created October 15, 2014 14:54
Stateface mapping from full state name to letter
// cf. http://propublica.github.io/stateface/
var statefaceMap = {"Alaska":"A","Arizona":"D","Arkansas":"C","California":"E",
"Colorado":"F","Connecticut":"G","Delaware":"H","Florida":"I","Georgia":"J",
"Hawaii":"K","Idaho":"M","Illinois":"N","Indiana":"O","Iowa":"L","Kansas":"P",
"Kentucky":"Q","Louisiana":"R","Maine":"U","Maryland":"T","Massachusetts":"S",
"Michigan":"V","Minnesota":"W","Mississippi":"Y","Missouri":"X","Montana":"Z",
"Nebraska":"c","Nevada":"g","New Hampshire":"d","New Jersey":"e",
"New Mexico":"f","New York":"h","North Carolina":"a","North Dakota":"b",
"Ohio":"i","Oklahoma":"j","Oregon":"k","Pennsylvania":"l","Rhode Island":"m",
"South Carolina":"n","South Dakota":"o","Tennessee":"p","Texas":"q",
@tophtucker
tophtucker / elasticScale.js
Created February 3, 2015 02:58
D3 elastic scale closure
// a wrapper around d3's linear scale;
// extreme inputs (outside domain) push the domain while maintaining a fixed extent
function elasticScale() {
var sensitivity = 27,
origin = 0,
domain = [origin - sensitivity/2, origin + sensitivity/2],
scale = d3.scale.linear()
.domain(padDomain(domain))
.range([0, 0, 1, 1])
.clamp(true);
@tophtucker
tophtucker / README.md
Last active August 29, 2015 14:19
Arrow connector helper

It is conceivable that one might want a setup whereby someone can arrange a Web Page such that certain things point to certain other things without writing any javascript or a ton of custom css or whatever. This is a solution.

1. HTML

In the data-arrow-target attribute of an HTML element, provide a CSS selector. If the selector matches more than one element, lines will be drawn from the element to all the matching elements.

E.g.: <div id="one" data-arrow-target="#two"></div>

2. JavaScript

function drawGCD(){
var stack = []
var a = 960 - Math.floor(Math.random()*100), b = 400 + Math.floor(Math.random()*100)
function gcd(u, v){
stack.push({u: u, v: v})
return v ? gcd(v, u % v) : u
}
@tophtucker
tophtucker / index.html
Last active August 29, 2015 14:27
Nested list columns
<!DOCTYPE html>
<meta charset="utf-8">
<style>
ul {
list-style-type: none; /* no bullets */
padding-left: 0; /* no spacing on left */
}
li {
clear: both; /* start a new line, kinda */
@tophtucker
tophtucker / README.md
Last active August 29, 2015 14:27
K-Hole

Factoring out the geometric background part of the opener for this Bloomberg Businessweek story on ketamine. Move your mouse left and right to change the speed. Move your mouse up and down to change the amplitude.

Text can be overlaid with the query string variable text, e.g. http://bl.ocks.org/tophtucker/raw/500d2a010105cfcc87db/?text=KETAMINE.

It's a bunch of concentric circles with exclusion compositing. The radius of the ith circle oscillates with amplitude * Math.sin(t/speed + (t/10000)*i), where t is the number of milliseconds since you loaded the page.

E.g., for amplitude = 5 and speed = 500 (which is the default if you position your mouse in the middle of the page), the radius of circle i at time t oscillates with period (20000π)/(20+i) in t ([WolframAlpha](http://www.wolframalpha.com/input/?i=5*sin%28t%2F500+%2B+%28t%2F10000%29*i%

@tophtucker
tophtucker / README.md
Last active September 23, 2015 19:25
Earth orbit

Click to fast-forward. Based on the math here. No guarantees of accuracy, this is not legal advice. Made in honor of Pi Day — which I think is borderline numerology, a random and arbitrary mapping, but I respect the ability to create meaning in life ex nihilo.