Skip to content

Instantly share code, notes, and snippets.

@mthh
mthh / getBorders_toGeo.pyx
Last active November 3, 2016 08:59
Get Borders to GeoJSON
cdef list get_comm(list arc_a, list arc_b):
cdef:
list comm = []
int aa, bb
for aa in flatten_arc(arc_a):
for bb in flatten_arc(arc_b):
if aa < 0:
aa = ~aa
if bb < 0:
bb = ~bb
@mthh
mthh / README.md
Last active November 24, 2016 16:09
d3-custom-build

This is a demonstration of building a custom D3 v4 bundle using ES2015 modules and Rollup, following the example from https://gist.github.com/mbostock/bb09af4c39c79cffcde4.
This example exposes many field from the "regular" d3 object (but not all) and take into account some plugins (d3-selection-multi and d3-geo-projection).

To build:

npm install
npm run prepublish
@mthh
mthh / main.rs
Last active January 4, 2017 22:24
Maximal rectangle problem resolution in rust
struct Matrix(Vec<Vec<i32>>);
struct Pt {
x: i32,
y: i32
}
#[derive(Debug)]
struct Rect {
x: i32,
const BARS: &'static str = "▁▂▃▄▅▆▇█";
fn print_sparkline(s: &str){
let v = BARS.chars().collect::<Vec<char>>();
let line: String = s.replace(",", " ").split(" ")
.filter(|x| !x.is_empty())
.map(|x| v[x.parse::<f64>().unwrap().ceil() as usize - 1])
.collect();
println!("{:?}", line);
}
@mthh
mthh / pip_raycasting.rs
Last active January 12, 2017 21:02
Example using ray casting algorithm for point in polygon queries
// "Ray casting" ("crossing number" / "even-odd") algorithm for point in polygon queries
// Translation of https://rosettacode.org/wiki/Ray-casting_algorithm#Python
// Posted back on https://rosettacode.org/wiki/Ray-casting_algorithm#Rust
use std::f64;
use std::clone::Clone;
const _EPS: f64 = 0.00001;
const _MIN: f64 = f64::MIN_POSITIVE;
const _MAX: f64 = f64::MAX;
@mthh
mthh / .block
Last active March 20, 2017 11:01
Reprojection
license: gpl-3.0
@mthh
mthh / .block
Last active March 24, 2017 15:35
Graham scan convex hull animation
license: gpl-3.0
@mthh
mthh / .block
Last active March 29, 2017 21:35
Gnome sort
license: gpl-3.0
@mthh
mthh / .block
Last active March 31, 2017 23:25 — forked from mbostock/.block
Natural Earth II
license: gpl-3.0
height: 960
border: no
"use strict";
var sin = Math.sin,
cos = Math.cos,
tan = Math.tan,
acos = Math.acos,
asin = Math.asin,
atan2 = Math.atan2,
PI = Math.PI;
var ISEA_PLANE = Symbol('ISEA_PLANE'),