Skip to content

Instantly share code, notes, and snippets.

View romicofre's full-sized avatar
🐇

Romi romicofre

🐇
View GitHub Profile
@romicofre
romicofre / init_gists.sh
Created April 28, 2024 02:48
Admin Gists
#!/bin/bash
# clone all gists of the accou
# with url id
#for name in $( gh gist list | awk '{print $2}'); do gh gist clone $name; done;
# with description folder
#gh api \
@romicofre
romicofre / aws_create_user_by_list_terraform.tf
Last active July 2, 2023 21:10
AWS - Create a list users with Terraform resource
# Variables
variable "region"{
type = string
}
variable "email_list"{
type = list(string)
}
@romicofre
romicofre / var_class.scala
Created February 22, 2021 15:03
Get variable class (get type scala)
println(1.getClass)
println("Hello").getClass
println(println("Hello").getClass)
@romicofre
romicofre / Carga_datos_bigquery_Colab.ipynb
Last active February 1, 2021 01:24
Cargar datos desde Google Colab a Bigquery
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@romicofre
romicofre / add_partition_expiration.sql
Created June 30, 2020 13:56
Add expiration to partition BigQuery
ALTER TABLE `dataset.table`
SET OPTIONS (
partition_expiration_days=30
);
@romicofre
romicofre / firestore_to_pandas_dataframe.py
Created June 28, 2020 01:03
Load firestore table to pandas dataframe
import pandas as pd
from google.cloud import firestore
db = firestore.Client()
users = list(db.collection(u'users').stream())
users_dict = list(map(lambda x: x.to_dict(), users))
df = pd.DataFrame(users_dict)
@romicofre
romicofre / memory_usage.py
Created June 28, 2020 00:56
Memory usage in MB
def memory_usage():
"""
:return: memory usage in MB
"""
mem = psutil.Process(os.getpid()).memory_info().rss
return mem / 1024 ** 2
@romicofre
romicofre / parallel_with_pool.py
Created May 17, 2020 19:32
from multiprocessing import Pool
# Function to apply a function over multiple cores
@print_timing
def parallel_apply(apply_func, groups, nb_cores):
with Pool(nb_cores) as p:
results = p.map(apply_func, groups)
return pd.concat(results)
# Parallel apply using 1 core
parallel_apply(take_mean_age, athlete_events.groupby('Year'), 1)
@romicofre
romicofre / date_convertion.py
Created April 13, 2020 19:32
Convert date string format
fecha = "20200413191418"
objeto_fecha = datetime.strptime(fecha, '%Y%m%d%H%M%S').strftime('%Y-%m-%dT%H:%M:%S')
print(objeto_fecha)
print(type(objeto_fecha))
#result:
# 2020-04-13T19:14:18
# <class 'str'>
@romicofre
romicofre / add_environment_var.py
Last active September 9, 2019 20:22
add a enviornment var by default in code or shell
os.environ.setdefault("DEPLOY", "DEV")