This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sat May 28 15:05:46 2022 | |
@author: Rodrigo E. Principe | |
""" | |
import time | |
import random | |
# params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def match_format_string(format_str, s): | |
""" https://stackoverflow.com/questions/10663093/use-python-format-string-in-reverse-for-parsing | |
Match s against the given format string, return dict of matches. | |
We assume all of the arguments in format string are named keyword arguments (i.e. no {} or | |
{:0.2f}). We also assume that all chars are allowed in each keyword argument, so separators | |
need to be present which aren't present in the keyword arguments (i.e. '{one}{two}' won't work | |
reliably as a format string but '{one}-{two}' will if the hyphen isn't used in {one} or {two}). | |
We raise if the format string does not match s. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv, glob, argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-n", "--name", help="name of the resulting file") | |
args = parser.parse_args() | |
csv_list = glob.glob('*.csv') | |
result_name = args.name or 'merged.csv' | |
# get fieldnames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first list | |
a = [1, 2, 3, 4] | |
# second list | |
b = ['a', 'b'] | |
# expected list | |
exp = ['a1', 'a2', 'a3', 'a4', 'b1', 'b2', 'b3', 'b4'] | |
# WITHOUT list comprehension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Función para agregar al mapa todas las imagenes de una coleccion | |
// Argumentos: | |
// col: coleccion de imagenes | |
// viz: diccionario con los parametros de visualizacion | |
// ej: viz = {bands:["B3","B4","B5"], min:0, max:255} | |
var addLayerCol = function(col, viz) { | |
var lista = col.getInfo()["features"] | |
for (var i = 0; i < lista.length; i++) { | |
var id = lista[i]["id"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Code to write data read from a URL to a file | |
Based on an answer on SO: | |
http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python/22721 | |
""" | |
import urllib2 | |
mp3file = urllib2.urlopen("http://www.example.com/songs/mp3.mp3") |