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
@jgomo3
jgomo3 / reco.rst
Last active August 29, 2015 14:01
Recomendaciones para realizar el proyecto 2 de Algoritmos y Programación II-2013

Recomendaciones para el proyecto 2

Ésta es una lista de recomendaciones que me atrevo a realizar a los alumnos del primer semestre de Computación de la UCV (II-2013) acerca de cómo desarrollar el producto que se les exige en el segundo proyecto de la materia Algoritmos y Programación.

Estas recomendaciones están basadas en mi experiencia al realizar

@jgomo3
jgomo3 / hmf.md
Created October 7, 2014 02:25
Haskell Mind Fucks
  1. La desigualdad es /=. En los de los lenguajes de programación más populares, la desigualdad es !=, pero Haskel decidió utilizar /= y creemos que la razón es porque se parece más al símbolo matemático de la desigualdad: .
  2. El condicional if tiene que definir obligatoriamente el bloque else.
  3. El rango no se define por un paso, sino que se describe la secuencia en términos del primer y segundo elemento, para deducir el paso. Ejemplo: [1,4..] son los números del 1 en adelante de 3 en 3.
@jgomo3
jgomo3 / html2pres.py
Last active August 29, 2015 14:22
An HTML leaves stripping keeping certain elements
"""I downloaded the html5 version of PRO_GIT_book_ in order to review
with some partners the chapter dedicated to branching (chapter 3).
In order to guide a visual review of the chapter, i decided to grab
only the images and *code examples* and eliminate the rest.
The technique implemented is by striping the leaves off the *HTML DOM*
tree, expect those being `<img>`, `<code>` and `<h*>`. The containers
elements should not be deleted as it could damage the document
structure.
@jgomo3
jgomo3 / reglas.py
Created May 29, 2015 18:42
One YML to CSV merging keys and values in rows.
import yaml
import csv
from sys import stdout
salida = open('reglas.csv', 'w')
# salida = stdout
reglas = yaml.safe_load(open('reglas_de_negocio.yaml'))
campos = ['descripción', 'observaciones']
tabla = [
@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
@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 / 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 / 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 / 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 / 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]) + \