Skip to content

Instantly share code, notes, and snippets.

@ZJONSSON
ZJONSSON / README.md
Last active August 29, 2015 14:04
Optimal denominations

This small script uses combinatory analysis to figure out the optimal denominations for given number of possible coins to minimize the coins required to produce any amount between 1 cent and 1 dollar. The candidate set of denominations is reduced to keep the combinatory possibilities within reason.

@ZJONSSON
ZJONSSON / app.js
Last active August 29, 2015 14:04
Happy Birthday
function encode64(data) {
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var PAD = '=';
var ret = '';
var leftchar = 0;
var leftbits = 0;
for (var i = 0; i < data.length; i++) {
leftchar = (leftchar << 8) | data[i];
leftbits += 8;
while (leftbits >= 6) {

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
@ZJONSSON
ZJONSSON / index.html
Created October 1, 2011 19:36
Using data() enter and exit in D3
<!DOCTYPE html>
<html>
<head></head>
<body></body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript">
// Define the SVG domain in a viewbox to get automatic resize to
// window. This is a good alternative to d3.scale for simple stuff
svg=d3.select("body")
@ZJONSSON
ZJONSSON / index.html
Created October 5, 2011 00:20
SVG slippy map using Viewbox with D3
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="svg_interact.js"></script>
<script type="text/javascript" src="svg_map.js"></script>
</head>
<body></body>
@ZJONSSON
ZJONSSON / index.html
Created October 14, 2011 17:11
Update speed based on number of SVG elements in viewBox
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
</head>
<body>
<div id="graph"></div>
<div id="fps">FPS: <SPAN>?</SPAN></DIV>
Number or circles
@ZJONSSON
ZJONSSON / index.html
Created October 14, 2011 22:26
[separate SVG boxes ] Update speed based on number of SVG elements in viewBox
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<STYLE>svg { border: dashed;border-width:1px;}</STYLE>
</head>
<body>
<div id="graph"></div>
<div id="fps">FPS: <SPAN>?</SPAN></DIV>
@ZJONSSON
ZJONSSON / index.html
Created October 14, 2011 23:11
Update speed based on length of an unrelated static path object
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<STYLE>svg { border: dashed;border-width:1px;}</STYLE>
</head>
<body>
<div id="graph"></div>
<div id="fps">FPS: <SPAN>?</SPAN></DIV>
@ZJONSSON
ZJONSSON / index.html
Created October 17, 2011 00:51
Using D3 to create and animate X3D - with x3dom
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://x3dom.org/x3dom/example/x3dom.js"></script>
</head>
<body>
</body>
@ZJONSSON
ZJONSSON / index.html
Last active September 27, 2015 15:28
Simple X3D with D3
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://raw.github.com/mbostock/d3/v2.4.3/d3.js"></script>
<script type="text/javascript" src="http://x3dom.org/x3dom/example/x3dom.js"></script>
</head>
<body>
</body>