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 / creating-icons.js
Created July 9, 2012 12:01
Leaflet 0.3 -> 0.4 Icon API upgrade
// 0.3 way
var icon = new L.Icon('icon.png');
// 0.4 way
var icon = new L.Icon({iconUrl: 'icon.png'}); // or just "L.icon(...)"
@mourner
mourner / spaces-vs-tabs-js.md
Created November 7, 2012 11:33
Whitespace conventions of popular JS libraries

Whitespace Conventions of Popular JS Libraries

Manually sorted by browsing most starred JS projects on GitHub (client-side only, all the Node crowd uses 2 spaces).

2 spaces

  • Backbone
  • Underscore
  • D3
@mourner
mourner / index.html
Created November 15, 2012 21:22 — forked from tmcw/index.html
SVG points and 3d transforms
<!DOCTYPE html>
<meta charset="utf-8">
<title>SVG Swarm</title>
<style>
svg {
position: absolute;
top: 0;
}
@mourner
mourner / example.js
Created December 12, 2012 10:58
New in Leaflet master: AOP-style constructor hooks for all classes. Example:
L.Marker.addInitHook(function () {
// do some additional stuff in the constructor, e.g.:
this.on('click', doExcitingStuff);
// will be called for all instances of Marker
});
@mourner
mourner / patch.js
Created October 15, 2015 20:37
Temporary workaround for Leaflet 0.7.5 disappearing tiles on iOS
L.Map.prototype._onZoomTransitionEnd = function () {
if (!this._animatingZoom) { return; }
this._animatingZoom = false;
L.DomUtil.removeClass(this._mapPane, 'leaflet-zoom-anim');
L.Util.requestAnimFrame(function () {
this._resetView(this._animateToCenter, this._animateToZoom, true, true);
@mourner
mourner / bundle.js
Last active October 23, 2015 15:30
Visualization of color distance metrics
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var metrics = require('./metrics');
var len = 25;
var colors = [];
function randomizeColors() {
colors = [];
for (var i = 0; i < 500; i++) colors.push(randomColor());
}
~/projects/test → npm -v
2.14.4
~/projects/test → npm cache clean
~/projects/test → time npm install eslint
eslint@1.8.0 node_modules/eslint
├── escape-string-regexp@1.0.3
├── object-assign@2.1.1
├── path-is-absolute@1.0.0
├── path-is-inside@1.0.1
├── xml-escape@1.0.0
'use strict';
var fs = require('fs');
var path = require('path');
function lazyRead(path, chunkFn, done) {
var input = fs.createReadStream(path)
.on('readable', handleReadable)
.on('end', handleEnd);
@mourner
mourner / neural-2layers.js
Created November 30, 2015 20:19
A barebones 2-layer toy neural network in JS.
'use strict';
// ported from http://iamtrask.github.io/2015/07/12/basic-python-network/
const ndarray = require('ndarray');
const ops = require('ndarray-ops');
const matrix = (rows, cols, data) => ndarray(new Float32Array(data || (rows * cols)), [rows, cols]);
const sigmoid = (out, a) => {
@mourner
mourner / kml.js
Created December 18, 2012 11:04
Some old KML parsing code from CloudMade Web Maps API for @tmcw
CM.GeoXML.prototype = {
// ...
_parseKmlStyle: function(obj) {
var style = {};
if (obj.LineStyle) {
if (obj.LineStyle.color) {
var color = this._parseKmlColor(obj.LineStyle.color.$);
style.color = color.rgb;
style.opacity = color.opacity;
//TODO: colorMode=random