Skip to content

Instantly share code, notes, and snippets.

View dnmellen's full-sized avatar
🐙

Diego Navarro dnmellen

🐙
  • Madrid
View GitHub Profile
@dnmellen
dnmellen / flatten.py
Last active December 29, 2015 04:59
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)
else:
yield item
@dnmellen
dnmellen / inverval_dates.lua
Last active December 24, 2015 07:19
Returns an array of dates between two given dates. You can select the "step" (year, month, day)
-- 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 = {}
@dnmellen
dnmellen / function_tools.py
Created September 20, 2013 10:42
Calls a function and retries N times if there is an exception or the returned value by the function is *value_to_retry*
def retry(callable, callable_args, num_retries=5, sleep_time=0, value_to_retry='f9e40fdf355643dd82cea787ca2e8d3c04966855'):
"""
Calls a function and retries N times if there is an exception or the returned value by the function is *value_to_retry*
:param callable: What you want to execute
:type callable: python callable obj
:param callable_args: Callable's arguments
:type callable_args: tuple
:param num_retries: Numer of retries
:type num_retries: int
@dnmellen
dnmellen / test_views.py
Last active May 29, 2023 13:31
How to create a unittest for a "View" Mixin (Django Testing)
from django.test import TestCase, RequestFactory
from django.views.generic import TemplateView
from ..lib.views import YourMixin
class YourMixinTest(TestCase):
'''
Tests context-data in a Django Mixin like a boss
'''
@dnmellen
dnmellen / colors.py
Created May 15, 2013 13:32
Auxiliary Python module to get styled terminal outputs in a pythonic way
# encoding: utf-8
# Copyright 2013 Diego Navarro Mellén. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#