Skip to content

Instantly share code, notes, and snippets.

@DiegoTc
DiegoTc / rds_to_docker.md
Created March 15, 2020 22:51 — forked from herval/rds_to_docker.md
Moving a Postgres db from RDS to a Docker container

Make a backup from RDS

pg_dump -h <rds host> -p 5432 -F c -O -U <rds user> <db name> > db.dump

Restore the backup into a Docker container

docker run --rm --interactive --link <postgres container id>:postgres --volume $PWD/:/tmp/ postgres:latest /bin/bash -c 'pg_restore --verbose --clean --no-acl --no-owner -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres -d <db name> /tmp/db.dump'
@DiegoTc
DiegoTc / delete_all_awslogs.sh.md
Created February 17, 2020 19:10 — forked from pahud/delete_all_awslogs.sh.md
delete all aws log groups

specify the region

export AWS_DEFAULT_REGION=ap-northeast-1
aws logs describe-log-groups --query 'logGroups[*].logGroupName' --output table | \
awk '{print $2}' | grep -v ^$ | while read x; do  echo "deleting $x" ; aws logs delete-log-group --log-group-name $x; done

only delete loggroup name starting with /aws/lambda

# This is the normal destination variable to use. If you are running Ansible
# from outside EC2, then 'public_dns_name' makes the most sense. If you are
# running Ansible from within EC2, then perhaps you want to use the internal
# address, and should set this to 'private_dns_name'. The key of an EC2 tag
# may optionally be used; however the boto instance variables hold precedence
# in the event of a collision.
destination_variable = public_dns_name
# This allows you to override the inventory_name with an ec2 variable, instead
# of using the destination_variable above. Addressing (aka ansible_ssh_host)
@DiegoTc
DiegoTc / terraform-aws-wait-healthy.sh
Created November 7, 2019 03:12 — forked from ryane/terraform-aws-wait-healthy.sh
Waits for AWS instances launched from Terraform to become healthy
aws ec2 wait instance-status-ok --instance-ids $(cat terraform.tfstate | jq '.modules[].resources[] | select(.type == "aws_instance") | .primary.attributes.id' | sed 's/\"//g' | tr '\n', ' '; echo '')
@DiegoTc
DiegoTc / information.txt
Last active December 2, 2018 20:15
Change time zone postgresql
Choose a timezone from:
SELECT * FROM pg_timezone_names;
And set example:
ALTER DATABASE postgres SET timezone TO 'US/Central';
SELECT pg_reload_conf();
@DiegoTc
DiegoTc / file.txt
Created November 7, 2018 02:48
Connect_to_EC2
ssh -i YOUR-KEYPAIR.pem -L PORT:RDS-ENDPOINT:5432 ec2-user@YOUR-JUMPING-SERVER
PORT: THE ONE YOU DECIDE
RDS-ENDPOINT: DATABASE ENDPOINT
YOUR-JUMPING-SERVER : THE IP OF YOUR EC2 INSTANCE
@DiegoTc
DiegoTc / read-access.sql
Last active December 13, 2018 22:21 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@DiegoTc
DiegoTc / Ejercicio2.java
Created November 8, 2017 19:54
Respuestas de los ejercicios de los examenes
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package examenI;
import java.util.Scanner;
/**
*
* @author dturcios
import java.util.Scanner;
public class Ejercicio2{
public static void main(String[] args) {
int contador =0;
int sueldo =0;
int extra = 0;
int horas = 0;
Scanner Scanner = new Scanner(System.in);
while(contador <3){
System.out.print("Ingrese el total de horas trabajadas: ");
@DiegoTc
DiegoTc / Ceutec.java
Created November 1, 2017 13:15
Ejercicio de Victor Sandoval
public class Ceutec {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int x = Integer.parseInt(args [0]);
int resp = x;