This file contains hidden or 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 ensure_dir(f): | |
| d = os.path.dirname(f) | |
| if not os.path.exists(d): | |
| os.makedirs(d) | |
| return os.path.exists(f) |
This file contains hidden or 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 get_client_ip(request): | |
| x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') | |
| if x_forwarded_for: | |
| ip = x_forwarded_for.split(',')[0] | |
| else: | |
| ip = request.META.get('REMOTE_ADDR') | |
| return ip |
This file contains hidden or 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 chunks(l, n): | |
| """Yield successive n-sized chunks from l.""" | |
| for i in range(0, len(l), n): | |
| yield l[i:i + n] |
This file contains hidden or 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 logging | |
| def config_logging( | |
| filename, | |
| format='[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s', | |
| datefmt='%d/%b/%Y %H:%M:%S', | |
| level=logging.INFO): | |
| logging.basicConfig( | |
| filename=filename, |
This file contains hidden or 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 subprocess | |
| def run(cmd): | |
| p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) | |
| (output, err) = p.communicate() | |
| if err: | |
| raise RuntimeError() | |
| return output.decode('utf8').strip() |
This file contains hidden or 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
| sed -i -- 's/hello/moto/g' **/*(D.) | |
| sed -i 's/hello/moto/g' file.txt | |
| find /home/bruno/old-friends -type f -exec sed -i 's/ugly/beautiful/g' {} \; |
This file contains hidden or 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 connect_db(path): | |
| con = sqlite3.connect(path) | |
| con.row_factory = sqlite3.Row | |
| return con |
This file contains hidden or 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 expanduser | |
| home = expanduser("~") |
This file contains hidden or 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
| // ==UserScript== | |
| // @name block-operator-ad | |
| // @namespace liuzenglu | |
| // @description block-operator-ad | |
| // @version 1 | |
| // @grant none | |
| // ==/UserScript== | |
| if (window.location.href.startsWith("http://")) { | |
| var black_list = new Array( |
NewerOlder