Skip to content

Instantly share code, notes, and snippets.

View bubbobne's full-sized avatar
🏠
Working from home

Daniele Andreis bubbobne

🏠
Working from home
View GitHub Profile
@bubbobne
bubbobne / shp4timeManager.sh
Created November 14, 2018 13:43
export data in shp and use it with qgis timeManager
/*Export to shp file with select. Create a start and end date (weekly)*/
pgsql2shp -f "./test.shp" -h localhost -p 5432 -u **** -P ******* myDataBase "select table2.gid,table2.geom,data.* from (select id,survey_date,extract('week'from date) as dow ,date_trunc('week', date) as start_week,(date_trunc('week', date)+ '7 days'::interval) as end_week, value from table1) as data left join table2 on data.gid=table1.gid;"
@bubbobne
bubbobne / getStations.py
Last active September 25, 2018 08:57
get meteo trentino stations info by codice
import csv
import xml.etree.ElementTree
e = xml.etree.ElementTree.parse('listaStazioni.xml').getroot()
with open('./codiceStazioni.csv',newline="") as csvfile:
id_stazioni=csv.reader(csvfile,delimiter=",")
with open('./outputStazione.csv','w',newline="") as outFile:
out=csv.writer(outFile,delimiter=",")
header = ('codice', 'nome', 'nomebreve', 'quota','latitudine','longitudine','est','nord')
@bubbobne
bubbobne / eloquent_init.php
Last active June 15, 2018 12:11
Some useful statement to use eloquent
<?php
use Illuminate\Database\Capsule\Manager as DB;
/*
*Init eloquent illuminate
*
*DBDRIVER => "pgsql","sqlite","mysql"
*
*DBNAME is the complete path of the file if the driver is sqlite.
*/
$capsule = new DB();
@bubbobne
bubbobne / gulpfile.js
Last active May 11, 2018 12:55
Simple gulpfile to livereload angular project (dev mode) and build for production
/* jshint node:true */
'use strict';
var gulp = require('gulp');
var argv = require('yargs').argv;
var $ = require('gulp-load-plugins')();
var angularTemplatecache = require('gulp-angular-templatecache');
var del = require('del');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
from PIL import Image
import csv
immagine = Image.open(my_tiff_FILE)
pixels = list(map(lambda i: i*2,list(immagine.getdata())))
width, height = immagine.size
pixels = [pixels[i * width:(i + 1) * width] for i in range(height)]
print(pixels[0])
@bubbobne
bubbobne / usefullcmd.sh
Last active October 4, 2018 08:17
bash
//rename
rename 's/pattern/new_string/' <files>
//upper-to-lower
for i in *; do mv $i `echo $i | tr [:upper:] [:lower:]`; done
//get apache user name
APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1`
//set permission
sudo chmod g+rw "$APACHEUSER allow delete,write,append,file_inherit,directory_inherit" ./logs
def add_field_to_layer(layer, string_value, int_value, real_value):
for v in string_value:
print(v)
field_name = ogr.FieldDefn(v, ogr.OFTString)
field_name.SetWidth(24)
layer.CreateField(field_name)
for v in int_value:
print(v)
f=ogr.FieldDefn(v, ogr.OFTInteger)
layer.CreateField(f)
def get_request_to_json(url, user_name, user_password):
auth_string = '%s:%s' % (user_name, user_password)
base64string = base64.b64encode(auth_string.encode('ascii'))
headers = {'Authorization': "Basic %s" % bytes.decode(base64string)}
try:
req = urllib.request.Request(url, None, headers)
response = urllib.request.urlopen(req)
return json.loads(bytes.decode(response.read()))
except IOError as e:
print(e)
@bubbobne
bubbobne / utility.js
Created July 13, 2017 08:56
utility per javascript
/**
* Add the time zone offset to a data.
*
*
* @param {Date} data - The Date to transform.
*/
function getDataWithOffset(data){
var tzoffset = (new Date()).getTimezoneOffset() * 60000;
return new Date(data - tzoffset);
#git config --global core.editor nano
git config --global user.name ""
git config --global user.email ""
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"