Skip to content

Instantly share code, notes, and snippets.

View carlos-jenkins's full-sized avatar

Carlos Jenkins carlos-jenkins

View GitHub Profile
@carlos-jenkins
carlos-jenkins / secret_key.py
Created August 27, 2015 00:24
Generate Django SECRET_KEY
from django.utils.crypto import get_random_string
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
if __name__ == '__main__':
print(get_random_string(50, chars))
@carlos-jenkins
carlos-jenkins / submodules.py
Created September 15, 2015 10:52
Find all submodules given a module root name
def get_modules(name):
"""
Get a list of all submodules given a module root name.
"""
from pkgutil import walk_packages
module = __import__(name)
# Handle modules installed in top-level
if not hasattr(module, '__path__'):
return [(name, False)]
submodules = [(name, True)]
@carlos-jenkins
carlos-jenkins / test_metaclass.py
Created December 2, 2015 23:24
Use metaclass to wrap methods in a object using a decorator.
from six import add_metaclass
def print_decorator(func):
def replacement(*args, **kwargs):
result = func(*args, **kwargs)
print('The result of the function is: {}'.format(result))
return result
return replacement
@carlos-jenkins
carlos-jenkins / editors.rst
Last active March 7, 2019 19:50
Sublime Text and Atom Setup for Ubuntu
@carlos-jenkins
carlos-jenkins / mkstemp.py
Created April 13, 2016 00:39
Creating named temporal files in Python
from os import fdopen
from json import dumps
from tempfile import mkstemp
payload = {'one': 1}
osfd, tmpfile = mkstemp()
with fdopen(osfd, 'w') as pf:
pf.write(dumps(payload))
@carlos-jenkins
carlos-jenkins / multihooks.py
Last active August 10, 2023 22:12
Delegating script for multiple git hooks
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2015-2017 Carlos Jenkins <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@carlos-jenkins
carlos-jenkins / runonhost
Last active May 4, 2016 18:07
Python script that allows to run commands in the host from inside a Vagrant container using SSH
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from os import getcwd
from json import loads
from sys import argv, stdout
from shlex import split as shsplit
from os.path import expanduser, isfile, relpath, join
from subprocess import check_output, CalledProcessError, Popen, PIPE
@carlos-jenkins
carlos-jenkins / add_cert.sh
Created May 19, 2016 20:15
Download and add SSL certificate to shared system NSS database. A.k.a how the fuck do you add a certificate to Chrome/Chromium.
#!/usr/bin/env bash
set -o errexit
set -o nounset
# set -o xtrace
DOMAIN=${1:-}
@carlos-jenkins
carlos-jenkins / issues.py
Created September 26, 2016 21:53
Get open/closed Github issues and pull requests
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from logging import getLogger as get_logger # noqa
from datetime import datetime
from github import Github
log = get_logger(__name__)