Skip to content

Instantly share code, notes, and snippets.

Diego Navarro dnmellen

Block or report user

Report or block dnmellen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
dnmellen /
Last active Mar 9, 2019
DynamoDB mixin for Django models: Mix Django fields and DynamoDB fields in your models!
import uuid
import boto3
from decimal import Decimal
from functools import partial
from django.db import models
from django.conf import settings
class UUIDModel(models.Model):
dnmellen /
Created Jan 31, 2017
AWS Lambda function that performs an ssh command through a bastion server to another server. The function will be triggered by a Cloudwatch Alarm
import json
import boto3
import paramiko
def worker_handler(event, context):
dnmellen /
Last active Jul 2, 2019
Simple template filter for django to convert numbers to cool format (2.3K, 4M, etc..)
from django import template
register = template.Library()
def cool_number(value, num_decimals=2):
Django template filter to convert regular numbers to a
cool format (ie: 2K, 434.4K, 33M...)
dnmellen /
Created Jan 15, 2015
Seconds to the next day in python
from datetime import datetime, timedelta
print (datetime(*( + timedelta(days=1)).timetuple()[:3]) -
dnmellen /
Created Jan 23, 2014
Threaded timeout Python decorator
import threading
import logging
from functools import wraps
logger = logging.getLogger(__name__)
def timeout(secs=None):
def my_decorator(target, *args, **kwargs):
dnmellen /
Created Jan 15, 2014
Listen Redis pubs with python3 and asyncio
import asyncio
import redis
def listener(redis_conn, channels):
pubsub = redis_conn.pubsub()
print('Listening redis...')
dnmellen /
Last active Jan 2, 2016
Takes an screenshot (the user draws a rectangle to select the interesting area), scans the resulting image and copy the text to clipboard
#!/usr/bin/python -tt
Takes an screenshot (the user draws a rectangle to select the interesting area), scans the resulting image and copy the text to clipboard
- scrot (
- readbot (`pip install readbot`)
- pyperclip (`pip install pyperclip`)
dnmellen /
Last active Dec 30, 2015
Post installation PostgresSQL

Useful things to do after postgresql installation

# su - postgre
$ createuser youruser
$ psql
postgres=# ALTER USER youruser WITH PASSWORD 'yoursecretpassword';
postgres=# CREATE DATABASE yourdb owner youruser;
dnmellen /
Last active Dec 29, 2015
My try for "flatten" with yield from
from collections import Iterable
def flatten(iterable):
for item in iterable:
if isinstance(item, Iterable):
yield from flatten(item)
yield item
dnmellen / inverval_dates.lua
Last active Dec 24, 2015
Returns an array of dates between two given dates. You can select the "step" (year, month, day)
View inverval_dates.lua
-- Returns an array of dates between `date1` and `date2`
-- The 'step' between dates it can be selected with 3 possible values:
-- (year, month, day)
-- ie: get_interval_dates(20130101, 20130601, "month")
-- -> (201301, 201302, 201303, 201304, 201305, 201306)
-- Diego Navarro (dnmellen)
function get_interval_dates(date1, date2, step)
local result = {}
You can’t perform that action at this time.