Skip to content

Instantly share code, notes, and snippets.

@gagan-bansal
gagan-bansal / svg2geojson
Created November 24, 2014 16:37
svg to geojson approach
// svg file detail
var width = 400;
var height = 400;
// svg file spatial extent, you should know these values for your file
var extent = {left: -180, bottom: 90, right: 180, top: 90};
var x_res = (extent.left - extent.right) / width;
var y_res = (extent.left - extent.right) / height;
// x_res and y_res should be same
@gagan-bansal
gagan-bansal / README.md
Created April 27, 2015 07:19
myscripts

my scripts

some scripts for various work

@gagan-bansal
gagan-bansal / app.js
Created September 9, 2013 13:02
sample express with browserify-middleware app.js
var browserify = require('browserify-middleware');
var express = require('express');
var app = express();
browserify.settings.development('basedir', __dirname);
app.use('/js',browserify('./client'));
app.get('/js/main.js', browserify('./client/main.js',{
external: ['OpenLayers'],
detectGlobals: false
}));
@gagan-bansal
gagan-bansal / index.html
Created September 9, 2013 13:16
express with browserify-middleware index.html
<html>
<head>
<script type="text/javascript" src="/js/main.js"></script>
<style>
#map {
width:600px;
height:400px;
}
</style>
</head>
@gagan-bansal
gagan-bansal / main.js
Created September 9, 2013 13:18
express with browserify-middleware main.js
window.OpenLayers = require('./OpenLayers.js');
window.init = function() {
var osm = new OpenLayers.Layer.OSM();
osm.wrapDateLine = false;
var map = new OpenLayers.Map("map",{projection:'EPSG:900913',numZoomLevels:18});
map.addLayers([osm]);
map.setCenter(new OpenLayers.LonLat(8126483.8753499,2162623.286343),15);
console.log('init function called');
};
@gagan-bansal
gagan-bansal / ex1.bas
Created November 4, 2017 12:14
ex1 created by GaganBansal - https://repl.it/NjwU/1
PRINT "Enter the password"
INPUT WORD$
IF WORD$ = "SECRET" THEN
PRINT "permission granted"
ELSE
PRINT "permission denied": GOTO goend
END IF
PRINT "what should I call you"
INPUT name
@gagan-bansal
gagan-bansal / calculate-google-maps-resolutions.js
Created January 20, 2015 12:29
Calculate google maps (or web mercator projection) zoom level resolutions.
var extent = {
left: -20037508.342789244,
right: 20037508.342789244,
bottom: -20037508.342789244,
top: 20037508.342789244
};
var size = 256; // map tile size
var resolutions = [];
for (var i=0; i< 24; i++) {
resolutions.push( (extent.right - extent.left) / (256 * Math.pow(2,i)) );
@gagan-bansal
gagan-bansal / for-await-of.js
Last active June 16, 2022 04:43
Understanding "for await...of"
const arr = []
const dummy = async function (i) {
return new Promise((res, rej) => {
const delay = Math.random() * 1000
setTimeout(() => {
console.log('%s, delayed: %s, timestamp: %s', i, delay, Date.now());
res(i);
}, delay);
});
@gagan-bansal
gagan-bansal / catch-exception-and-promise-rejection.js
Created July 2, 2022 03:07
How to catch both thrown error as well as Promise rejection
(async () => {
console.log('Starting');
let result;
try {
result = await test();
} catch (error) {
// catch both thrown error as well as Promise rejection
console.error(error);
}
console.log('Result: ', result);
@gagan-bansal
gagan-bansal / create-gz-file.js
Created July 14, 2022 05:41
Compress a file with gz using node.js zlib module.
const file = process.argv[2];
const {promisify} = require('util');
const zlib = require('zlib');
const gzip = promisify(zlib.gzip);
(async () => {
const fs = require('fs');
const data = fs.readFileSync(file, 'utf-8');
const buf = await gzip(data)