# su - postgre
$ createuser youruser
$ psql
postgres=# ALTER USER youruser WITH PASSWORD 'yoursecretpassword';
postgres=# CREATE DATABASE yourdb owner youruser;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Iterable | |
def flatten(iterable): | |
for item in iterable: | |
if isinstance(item, Iterable): | |
yield from flatten(item) | |
else: | |
yield item |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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`) | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import redis | |
@asyncio.coroutine | |
def listener(redis_conn, channels): | |
pubsub = redis_conn.pubsub() | |
pubsub.subscribe(channels) | |
print('Listening redis...') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import logging | |
from functools import wraps | |
logger = logging.getLogger(__name__) | |
def timeout(secs=None): | |
def my_decorator(target, *args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
print (datetime(*(datetime.now() + timedelta(days=1)).timetuple()[:3]) - datetime.now()).seconds |
OlderNewer