Skip to content

Instantly share code, notes, and snippets.

@mzur
mzur / ImageCanvas.js
Created October 24, 2018 12:10
OpenLayers ImageStatic with canvas source
import ImageStatic from 'ol/source/ImageStatic';
import ImageCanvas from 'ol/ImageCanvas';
import EventType from 'ol/events/EventType';
import {listen} from 'ol/events';
class Canvas extends ImageStatic {
constructor(options) {
super(options);
this.image_ = new ImageCanvas(options.imageExtent, 1, 1, options.canvas);
listen(this.image_, EventType.CHANGE, this.handleImageChange, this);

Here's the canonical TOML example from the TOML README, and a YAML version of the same. Which looks nicer?

title = "TOML Example"

[owner]

@korya
korya / Mercator Projection.js
Created March 8, 2017 16:01
Mercator Projection for Google Maps JS SDK
// Base tile size used in Google Javascript SDK
const GOOGLE_BASE_TILE_SIZE = 256;
// MercatorProjection implements the Projection interface defined in Google Maps
// Javascript SDK.
//
// Google Maps Javascript SDK docs:
// https://developers.google.com/maps/documentation/javascript/maptypes#WorldCoordinates
//
// For more details about the convertions see
@timneutkens
timneutkens / index.js
Last active March 4, 2024 14:01
Clear console/terminal in node.js the right way
const readline = require('readline')
const blank = '\n'.repeat(process.stdout.rows)
console.log(blank)
readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout)
@dropmeaword
dropmeaword / corsproxy.php
Last active July 16, 2024 01:28
simple CORS proxy in php
<?php
error_reporting( error_reporting() & ~E_NOTICE ); // evil
// config
$enable_jsonp = false;
$enable_native = false;
$valid_url_regex = '/.*/';
// ############################################################################
'use strict';
const X = [0.1, 0.5, 0.9, 1.3, 1.7];
const Y = [-2.3026, -0.69315, -0.10536, 0.26236, 0.53063];
const x = 0.8;
// const n = 3;
// var splines = new Array(X.length).fill({a:null,b:null,c:null,d:null,x:null});
var splines = [];
for (let i =0; i < X.length; i++){
splines.push({a:null,b:null,c:null,d:null,x:null});
@loon3
loon3 / 0-json_to_webtorrent.js
Last active January 15, 2019 09:27
Convert json data to webtorrent and seed, then download json from webtorrent
//jQuery and Webtorrent (https://webtorrent.io/) dependencies
var json_source_url = ""; //json data source
var filename = ""; //filename.json
$.getJSON(json_source_url, function( data ) {
var jsonstring = JSON.stringify(data);
var blob = new Blob([jsonstring], {type: "application/json"});
var client = new WebTorrent()
@mfuerstenau
mfuerstenau / zigzag-encoding.README
Last active October 17, 2024 04:35
ZigZag encoding/decoding explained
ZigZag-Encoding
---------------
Maps negative values to positive values while going back and
forth (0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6 ...)
(i >> bitlength-1) ^ (i << 1)
with "i" being the number to be encoded, "^" being
XOR-operation and ">>" would be arithemtic shifting-operation
@knugie
knugie / cancelAllRequestAnimFrame.js
Created October 10, 2014 03:39
cancel all request animation frames
window.cancelRequestAnimFrame = ( function() {
return window.cancelAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame ||
clearTimeout
} )();
for (var i = 1; i < 99999; i++) {
@6174
6174 / Random-string
Created July 23, 2013 13:36
Generate a random string in JavaScript In a short and fast way!
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);