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 os.path import commonprefix | |
def common_suffix(titles): | |
""" Return the common suffix of all the strings contained in the | |
argument list. | |
:param titles: a list of strings | |
Example: | |
>>> titles = [u'Homepage | wondercity', u'Page 1 | wondercity'] |
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
# Regex finding all dots in all keys of a JSON structure | |
DOT_IN_DICT_KEY = re.compile(r"""[,{] # opening bracket for first keys, or previous comma | |
\s* # spaces until first key quote | |
['"]([^.'"]+\.[^'"]+)['"] # key name in bewteen quotes | |
\s*:""", # : after key name , | |
flags=re.UNICODE | re.VERBOSE) | |
def dotrepl(matchobj): | |
"""Replace all . by _ in the match""" |
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
{ | |
"metadata": { | |
"name": "birthday-paradox" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ |
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
#!/bin/bash | |
# Check for uncommented debug patterns (pdb, ipdb, rdb) in python files. | |
# If such patterns are matched, prevent the commit | |
PATTERN="^[^#]*(i?pdb|rdb)" | |
debug_statements=`ack $PATTERN --py` | |
if [ -z "$debug_statements" ];then | |
exit 0 | |
else |
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
# The git user will run this script as a post-receive hook on the blog repository. | |
# It will build the latest version of the blog, and then copy it to the webserver directory | |
# This script is contained in the hooks/post-receive hook file of a git bare repository | |
# created with ``git init --bare``* | |
# We assume that pelican is installed globally, along with its dependencies. | |
BLOG_DIR=/var/www/blog | |
TMP_BLOG_CLONE=$HOME/blog-tmp | |
BLOG_GIT=/home/git/blog.git |
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
#!/bin/bash | |
PAGE_DIR=/var/www/ | |
TMP_PAGE_CLONE=$HOME/page-tmp | |
PAGE_GIT=/home/git/page.git | |
PAGE=$TMP_PAGE_CLONE/index.html | |
CURRENT_AGE=`python -c 'from datetime import date;print(date.today() - date(1990, 11, 4)).days / 365'` | |
CURRENT_YEAR=`date +%Y` |
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
class CoolDict(dict): | |
"""A dict that returns an empty CoolDict if a key is not found. | |
It litterally goes: 'Can't find your thing, but that's cool, don't care.' | |
Example: | |
>>> d = CoolDict() | |
>>> d['value1']['value2'].get('value3', 0) | |
0 |
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
### Keybase proof | |
I hereby claim: | |
* I am brouberol on github. | |
* I am brouberol (https://keybase.io/brouberol) on keybase. | |
* I have a public key whose fingerprint is 2E29 FBDD 51F3 D3F6 74D1 9B3D 52BA BA41 74FC 6BD7 | |
To claim this, I am signing this object: |
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 celery import Task | |
class ChainedTask(Task): | |
abstract = True | |
def apply_async(self, args, kwargs, **options): | |
"""Injects the dict return value of a a task as keyword args of the next one.""" | |
if args: | |
# handle the case of a bound task (decorated with bind=True) |
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 requests | |
from flask import Flask, request, Response, stream_with_context | |
from functools import wraps | |
app = Flask('test', static_folder=None) | |
def check_auth(username, password): |
OlderNewer