Skip to content

Instantly share code, notes, and snippets.

View fabiojwalter's full-sized avatar
🚀
Moving...

Fabio J. Walter fabiojwalter

🚀
Moving...
View GitHub Profile
@fabiojwalter
fabiojwalter / postresql_user_creation.sql
Created February 10, 2023 19:58
PostreSQL restricted user creation
--Dropping schema public
DROP SCHEMA public CASCADE;
-- Removing access from other users
REVOKE connect ON DATABASE ${dbName} FROM PUBLIC;
-- Creating schema
CREATE SCHEMA ${schemaName} AUTHORIZATION ${userName};
-- Grant privileges for user on schema
GRANT ALL ON ALL TABLES IN SCHEMA ${schemaName} TO ${userName};
GRANT ALL ON ALL SEQUENCES IN SCHEMA ${schemaName} TO ${userName};
/*=== To set default privileges for future objects ===*/
@fabiojwalter
fabiojwalter / start_instance.py
Created June 23, 2021 00:45
AWS - Lambda - EC2 Start
import boto3
region = 'us-west-2'
def lambda_handler(event, context):
instances = event['instance']
ec2 = boto3.client('ec2', region_name=region)
ec2.start_instances(InstanceIds=[instances])
print 'stopped your instances: ' + str(instances)
@fabiojwalter
fabiojwalter / stop_instance.py
Created June 23, 2021 00:43
AWS - Lambda - EC2 Stop
import boto3
region = 'us-west-2'
instances = ['i-091e60ababe060baa']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
print 'Desligando a Instancia: ' + str(instances)
@fabiojwalter
fabiojwalter / policy.json
Created June 23, 2021 00:42
AWS Policy - Lambda - EC2 Start/Stop
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
@fabiojwalter
fabiojwalter / Variables_As_Factors.R
Last active October 17, 2020 22:59
R Language - Convert features to Factors and Analyze them
library(tidyverse)
library(summarytools)
df <- churn %>%
mutate_if(sapply(churn, is.character), as.factor) %>%
mutate_if(sapply(churn, is.double), as.factor)
dfSummary(df, style = "grid", justify = "r", round.digits = 2)
@fabiojwalter
fabiojwalter / ListRoutes.js
Last active October 17, 2020 22:40
NodeJS - List Routes
const express = require("express");
const app = express();
app.get("/apis", (req, res) => {
let get = app._router.stack.filter(r => r.route && r.route.methods.get).map(r => r.route.path);
let post = app._router.stack.filter(r => r.route && r.route.methods.post).map(r => r.route.path);
let put = app._router.stack.filter(r => r.route && r.route.methods.put).map(r => r.route.path);
let del = app._router.stack.filter(r => r.route && r.route.methods.del).map(r => r.route.path);
res.send({ "get": get, "post": post, "delete": del, "put": put});
});
@fabiojwalter
fabiojwalter / postgresql_tables.sql
Created August 4, 2020 17:17
SQL Query - List PostgreSQL tables per schema
select table_schema,
table_name,
ordinal_position as position,
column_name,
data_type,
case when character_maximum_length is not null
then character_maximum_length
else numeric_precision end as max_length,
is_nullable,
column_default as default_value
@fabiojwalter
fabiojwalter / recursive.sql
Created August 4, 2020 17:12
SQL Query - Hierarchical user structure
WITH RECURSIVE subordinates AS (
SELECT
ur.user_id,
ur.owner_id
FROM
users.user_roles ur
WHERE
ur.user_id = 87 --DESIRED USER ID
UNION
SELECT