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
dnmellen / models.py
Last active Mar 9, 2019
DynamoDB mixin for Django models: Mix Django fields and DynamoDB fields in your models!
View models.py
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
dnmellen / worker_function.py
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
View worker_function.py
import json
import boto3
import paramiko
def worker_handler(event, context):
ALLOWED_HOSTS = [
'host1',
'host2,
@dnmellen
dnmellen / numbers.py
Last active Apr 30, 2019
Simple template filter for django to convert numbers to cool format (2.3K, 4M, etc..)
View numbers.py
from django import template
register = template.Library()
@register.filter
def cool_number(value, num_decimals=2):
"""
Django template filter to convert regular numbers to a
cool format (ie: 2K, 434.4K, 33M...)
@dnmellen
dnmellen / seconds.py
Created Jan 15, 2015
Seconds to the next day in python
View seconds.py
from datetime import datetime, timedelta
print (datetime(*(datetime.now() + timedelta(days=1)).timetuple()[:3]) - datetime.now()).seconds
@dnmellen
dnmellen / timeout_decorator.py
Created Jan 23, 2014
Threaded timeout Python decorator
View timeout_decorator.py
import threading
import logging
from functools import wraps
logger = logging.getLogger(__name__)
def timeout(secs=None):
def my_decorator(target, *args, **kwargs):
@dnmellen
dnmellen / redis_listener.py
Created Jan 15, 2014
Listen Redis pubs with python3 and asyncio
View redis_listener.py
import asyncio
import redis
@asyncio.coroutine
def listener(redis_conn, channels):
pubsub = redis_conn.pubsub()
pubsub.subscribe(channels)
print('Listening redis...')
@dnmellen
dnmellen / ocrshot.py
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
View ocrshot.py
#!/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 (http://en.wikipedia.org/wiki/Scrot)
- readbot (`pip install readbot`)
- pyperclip (`pip install pyperclip`)
"""
@dnmellen
dnmellen / postinstall.md
Last active Dec 30, 2015
Post installation PostgresSQL
View postinstall.md

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
dnmellen / flatten.py
Last active Dec 29, 2015
My try for "flatten" with yield from
View flatten.py
from collections import Iterable
def flatten(iterable):
for item in iterable:
if isinstance(item, Iterable):
yield from flatten(item)
else:
yield item
@dnmellen
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.