Skip to content

Instantly share code, notes, and snippets.

View juanmhidalgo's full-sized avatar

Juan M. Hidalgo juanmhidalgo

  • Mar del Plata, Buenos Aires, Argentina
View GitHub Profile
@juanmhidalgo
juanmhidalgo / https-instance.config
Created February 11, 2019 19:37
Config file to add https to beanstalk instance without load balancer using letsencrypt - Apache
Resources:
sslSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
FromPort: 443
CidrIp: 0.0.0.0/0
@juanmhidalgo
juanmhidalgo / pre-commit
Created April 18, 2018 20:29
Pre commit with flake8 and isort
#!/bin/bash
reset='\033[0m'
bold='\033[1m'
dim='\033[2m'
bg_black='\033[40m'
yellow='\033[33m'
COUNTER=0
COUNTER_SORT=0

Keybase proof

I hereby claim:

  • I am juanmhidalgo on github.
  • I am juanmhidalgo (https://keybase.io/juanmhidalgo) on keybase.
  • I have a public key ASCfBU_Vvl3YdV60konL0fxh2_Lvfva8csEldxW4rDl46Qo

To claim this, I am signing this object:

@juanmhidalgo
juanmhidalgo / monthly_range.py
Created January 24, 2017 07:43
Monthly iterate between two dates
import calendar
from datetime import datetime, timedelta
def monthly_range(dt_start, dt_end):
forward = dt_end >= dt_start
finish = False
dt = dt_start
while not finish:
yield dt.date()
@juanmhidalgo
juanmhidalgo / days_of_month.py
Created January 23, 2017 23:02
Get days of month
def get_days_of_month(year, month):
import calendar
return calendar.monthrange(year,month)[1]
#!/usr/bin/perl -w
use strict;
use IO::Socket::INET;
use IO::Socket::SSL;
use Getopt::Long;
use Config;
$SIG{'PIPE'} = 'IGNORE'; #Ignore broken pipe errors
print <<EOTEXT;
;(function() {
window.throttle = function (type, name, obj) {
obj = obj || window;
var running = false;
var func = function () {
if (running) { return; }
running = true;
requestAnimationFrame(function () {
var event;
@juanmhidalgo
juanmhidalgo / utils.py
Created March 11, 2016 19:08
[django] Render template to string
from django.template.loader import render_to_string
email_body = render_to_string("my_email_template.txt", { 'name': 'Bob',
'message': 'Hello!' })
@juanmhidalgo
juanmhidalgo / pas.py
Created March 9, 2016 14:15
Password Generator
import os
import string
def random_password(length=10):
chars = string.ascii_uppercase + string.digits + string.ascii_lowercase
password = ''
for i in range(length):
password += chars[ord(os.urandom(1)) % len(chars)]
return password
@juanmhidalgo
juanmhidalgo / utils.py
Created March 2, 2016 16:41
[django] Model to dict
from django.db.models.fields.related import ManyToManyField
def to_dict(instance):
opts = instance._meta
data = {}
for f in opts.concrete_fields + opts.many_to_many:
if isinstance(f, ManyToManyField):
if instance.pk is None:
data[f.name] = []
else: