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 / check_geometry.py
Last active March 12, 2024 13:47
Check if the centroid of a sub-basin is outside the polygon. If so create a new representative point #geoframe
#MIT License
#
#Copyright (c) 2017 Daniele Andreis
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
@bubbobne
bubbobne / dati_idrometro.ipynb
Last active September 1, 2020 17:05
dati_idrometro
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
library(tidyverse)
library(caret)
#' Predict values from an ordinal brm regression model.
#'
#' @param model the fitted model.
#' @param data a datafram with all explanatory variables and labels.
#' @return a dataframe with a probability value for each labels, for each item, and true value.
#' @examples
#' add(1, 1)
import itertools
# permutazioni
a = [2,4,6,8]
permutations = list(itertools.permutations(a))
# permutazioni per gruppi di 2
permutations = list(itertools.permutations(a,2))
# combinazioni
combinations = list(itertools.combination(a,2))
combinations = list(combinations_with_replacement(a,2))
@bubbobne
bubbobne / ipynb_drop_output.py
Last active March 26, 2019 13:10 — forked from pbugnion/ ipython_notebook_in_git.md
Keeping IPython notebooks under Git version control
#!/usr/bin/env python
"""
Suppress output and prompt numbers in git version control.
This script will tell git to ignore prompt numbers and cell output
when looking at ipynb files if their metadata contains:
"git" : { "suppress_output" : true }
@bubbobne
bubbobne / UsbDecoder.java
Last active August 29, 2019 12:50
deccode data from a magnetic striped card data
package org.andreis.daniele.myApp;
import android.util.Log;
/**
* Created by daniele
*/
public class UsbDecoder {
private String rawData = null;
library(rgeos)
library(maptools)
trentino_crs=CRS('+init=epsg:32632')
#create a list of polygomns
spatialPolygonList=lapply(seq_along(wkt_list), function(i) {
a=readWKT(wkt_list[i,]$WKT,p4s=trentino_crs)
a@polygons[[1]]@ID=as.character(i)
return(a)
})
# join polygons in 1 SpatialPolygons
@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();