Skip to content

Instantly share code, notes, and snippets.

View mourner's full-sized avatar
🔥
making stuff faster

Volodymyr Agafonkin mourner

🔥
making stuff faster
View GitHub Profile
@mourner
mourner / vector_tile.js
Last active August 29, 2015 14:12
How a generated pbf encoding/decoding code should look
'use strict';
exports.Tile = {read: readTile, write: writeTile};
exports.Layer = {read: readLayer, write: writeLayer};
exports.Feature = {read: readFeature, write: writeFeature};
exports.Value = {read: readValue, write: writeValue};
// decoding vector tile
function readTile(pbf, end) {
@mourner
mourner / test.js
Last active August 29, 2015 14:15
simple benchmarking snippet for v8 & node
function test() {
for (var i = 0, array = []; i < 1000; i++) array.push(i, i);
}
var start = Date.now(), ops = 0;
do { test(); ops++; } while (Date.now() - start < 1000);
(typeof console !== 'undefined' ? console.log : print)(ops + ' ops/s');
@mourner
mourner / bench-node.js
Last active August 29, 2015 14:15
A simple benchmark snippet for Node; simple alternative to benchmark.js
var start = now(),
ops = 0;
while (now() - start < 1) {
// [...] routine to bench goes here
ops++;
}
console.log(Math.round(ops / (now() - start)) + ' ops/s');
@mourner
mourner / earcut.d.ts
Last active August 29, 2015 14:15
mapbox/earcut type definitions
// TypeScript type definitions to use for reference when porting Earcut to other languages
declare module 'earcut' {
interface Point extends Array<number> {}
interface Ring extends Array<Point> {}
interface Polygon extends Array<Ring> {}
interface Triangles extends Array<Point> {}
diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js
index d98994f..596d47f 100644
--- a/src/layer/tile/GridLayer.js
+++ b/src/layer/tile/GridLayer.js
@@ -301,26 +301,29 @@ L.GridLayer = L.Layer.extend({
},
_viewReset: function (e) {
- var map = this._map;
- this._reset(map.getCenter(), map.getZoom(), e && e.hard);
@mourner
mourner / index.html
Last active August 29, 2015 14:16
reqAnimFrame animation vs CSS transition performance
<!DOCTYPE html>
<html>
<head>
<title>Animation Test</title>
<style>
html, body {
height: 100%;
}
button {
/*
@class Control.Attribution
@aka L.Control.Attribution; @inherits Control
The attribution control allows you to display attribution data in a small text box on a map.
It is put on the map by default unless you set its [`attributionControl` option](#map-attributioncontrol) to `false`,
and it fetches attribution texts from layers with the [`getAttribution` method](#layer-getattribution) automatically.
Extends Control.
*/
@mourner
mourner / equation.html
Created July 7, 2011 13:50
Brute-force JS solution for Xopus task (see http://goo.gl/Zy0a9)
<!DOCTYPE html>
<head>
<title>Test</title>
</head>
<body>
<button onclick="displayResult()">Search</button>
<script>
var numEvals;
function displayResult() {
@mourner
mourner / convert.js
Created September 30, 2015 08:37
A proof of concept for efficient point encoding in vector tiles
var tile = require('./points.json');
tile.layers.forEach(function (layer) {
layer.id = [];
layer.geometry = [];
layer.tags = [];
var x0 = 0;
@mourner
mourner / current-api.js
Created July 3, 2012 10:07
Leaflet API simplification proposal
var map = new L.Map('map');
map.setView(new L.LatLng(51.505, -0.09), 13);
var cloudmade = new L.TileLayer('http://{s}.tile.cloudmade.com/.../{z}/{x}/{y}.png', {
attribution: '[...]'
});
map.addLayer(cloudmade);
var marker = new L.Marker(new L.LatLng(51.5, -0.09));
marker.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();