Skip to content

Instantly share code, notes, and snippets.

View jgomo3's full-sized avatar
🏠
Working from home

Jesús Gómez jgomo3

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am jgomo3 on github.
  • I am jgomo3 (https://keybase.io/jgomo3) on keybase.
  • I have a public key whose fingerprint is E8CA 7677 6DF0 F87E 23D7 21DA BE66 27F0 D1C6 243A

To claim this, I am signing this object:

@jgomo3
jgomo3 / schema_clone.py
Created June 7, 2017 18:39 — forked from rabbitt/schema_clone.py
PostgreSQL schema cloner (including data).
import psycopg2 as pg
from io import BytesIO
from collections import defaultdict
from contextlib import contextmanager
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED
READ_COMMIT = ISOLATION_LEVEL_READ_COMMITTED
AUTO_COMMIT = ISOLATION_LEVEL_AUTOCOMMIT
@jgomo3
jgomo3 / consolidar.sh
Created May 17, 2017 18:20
Concatena todos los PDF de una carpeta
#!/bin/sh
# consolidar.sh
#
# 10 de junio de 2016
# Concatena a los pdf de la carpeta `Preliminares` los pdf
# correspondientes con el mismo nombre en la carpeta `Respuestas`
# y el resultado lo genera con el mismo nombre en la carpeta
# Consolidados.
#
@jgomo3
jgomo3 / new_aggregates.sql
Last active September 9, 2016 02:28
Example of hypotetical FIRST, SECOND and NTH Agregate Function
CREATE TEMPORARY TABLE object_with_cases
(
id int,
case int
);
INSERT INTO object_with_cases
(id, case)
VALUES
(3, 1)
@jgomo3
jgomo3 / dlyprgrmr240e.py
Created November 9, 2015 15:42
Typoglycemia - Dailyprogrammers [2015-11-09] Challenge #240 [Easy]
import random
import re
import sys
def get_text(file):
return file.read()
def scramble(word):
return \
('' if len(word) == 0 else word[0]) + \
@jgomo3
jgomo3 / dlyprgrmr239i.py
Last active November 4, 2015 17:44
A Zero-Sum Game of Threes - Dailyprogrammers [2015-11-04] Challenge #239 [Intermediate]
import functools
@functools.lru_cache(maxsize=None)
def redu(n, s=0):
if n < 1 or s < -2 or s > 2:
return None
if n == 1:
if s == 0:
return [(1, 0)]
else:
@jgomo3
jgomo3 / dlyprgrmr239e.py
Created November 4, 2015 15:31
A Game of Threes - Dailyprogrammers [2015-11-02] Challenge #239 [Easy]
def redu(n, c):
return (n + c)//3
T = [0, -1, 1]
N = int(input())
while N > 1:
C = T[N%3]
R = redu(N, C)
@jgomo3
jgomo3 / dlyprgrmr235e.py
Last active October 28, 2015 22:39
Ruth-Aaron Pairs - Dailyprogrammers [2015-10-05] Challenge #235 [Easy]
#!/usr/bin/env python3
import unittest
def build_sieve(n):
"""Create the extended and optimized Sieve of Eratosthenes.
The size of the sieve is `N`
`sieve[i]`` is `0` if `i` is prime
@jgomo3
jgomo3 / fulsh-ip-tables.sh
Created October 20, 2015 20:38
Flush all iptables rules
#!/bin/sh
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
@jgomo3
jgomo3 / ejemplo-sql-cte.sql
Last active October 1, 2015 16:20
Comparación entre dos expresiones SQL, con y sin CTE
-- Sin CTE
select
nombre
, comp.cantidad_suma as cant_comp
, fact.cantidad_suma as cant_fact
from
productos as prod
, (select sum(cantidad) as cantidad_suma, producto from compras) as comp
, (select sum(cantidad) as cantidad_suma, producto from facturas) as fact
where