Skip to content

Instantly share code, notes, and snippets.

View stefanocudini's full-sized avatar
🏔️
working from Alps

Stefano Cudini stefanocudini

🏔️
working from Alps
View GitHub Profile
@stefanocudini
stefanocudini / place2.geojson
Last active May 22, 2019 08:25
place2.geojson
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stefanocudini
stefanocudini / leaflet-simple-control
Created March 4, 2019 14:59
leaflet simple control defined inline
var control = (function() {
var control = new L.Control({position:'topleft'});
control.onAdd = function(map) {
var adown = L.DomUtil.create('a','gpxdown');
adown.href = 'myfile.gpx';
adown.target = '_blank';
adown.title = "Download button";
return adown;
};
@stefanocudini
stefanocudini / mongodb_export_valued_fields.sh
Last active February 27, 2019 12:34
export documents in mongodb collection having only the fields valued
#!/bin/bash
#
# requirements:
# sudo npm install -g variety-cli
# sudo apt install mongo-tools jq
#
D=$1
C=$2
C2="${C}_min"
CF="${C2}.json"
@stefanocudini
stefanocudini / nthName.js
Last active January 10, 2019 12:32
return same name with added incremental number at tail
/**
* return same name with added incremental number at tail
* @param {String} name text to increment tail number
* @param {String} sep separator string from base name and number
* @return {String} incremented text
*/
function nthName(name, sep) {
sep = sep || '';
var m = name.match(/([^0-9]+)([0-9]+)$/),
nameo = m ? m[1] : name,
@stefanocudini
stefanocudini / getvars.js
Last active October 1, 2018 14:37
web scraping global javascript vars in nodejs
const Nightmare = require('nightmare')
const nightmare = Nightmare({
// show: true
});
var url = process.argv[2] || 'http://labs.easyblog.it/',
prop = process.argv[3] || undefined;
Object.byString = function(o, s) {
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--link href="style.css" rel="stylesheet" type="text/css" /-->
<style>
/* @import url('style.css'); */
#content {
@stefanocudini
stefanocudini / ascii2bin.php
Created January 7, 2018 14:19
php ascii to binary
#!/usr/bin/env php
<?php
$in = trim(fgets(STDIN));
$ir = str_split($in);
$out = '';
foreach($ir as $i) {
@stefanocudini
stefanocudini / bin2ascii.php
Created January 7, 2018 14:18
php binary to ascii
#!/usr/bin/env php
<?php
$in = trim(fgets(STDIN));
$ir = explode(' ', $in);
foreach($ir as $i) {
echo chr(bindec($i));
}
@stefanocudini
stefanocudini / L.GeoJSONAutoClear.js
Created July 4, 2017 17:49
Leaflet layer geojson self cleaning on zoom out
L.GeoJSONAutoClear = L.GeoJSON.extend({
options: {
autoclear: true,
zoomdiff: 2
},
_autoClear: function(e) {
if(this.getLayers().length) {
if(e.target.getZoom() < e.target.getBoundsZoom(this.getBounds())-this.options.zoomdiff)
this.clearLayers();
}