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 / setup.py
Created July 1, 2017 00:46
Cythonization of a pure Python package in setup.py
# Run me with:
# python3 setup.py bdist_wheel --cythonize
# ...
if '--cythonize' in argv:
from Cython.Build import cythonize
packaging = {
'ext_modules': cythonize('lib/**/*.py'),
}
@carlos-jenkins
carlos-jenkins / .bashrc
Last active May 30, 2017 06:08
Colored prompt for bash with git support
# Prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [\1]/'
}
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$\[\033[38;5;166m\]$(parse_git_branch)\[\033[00m\] '
# Less Colors for Man Pages
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
@carlos-jenkins
carlos-jenkins / args.py
Created May 16, 2017 20:35
Colored Logging
# Requires thrid-party awesome module colorlog
import logging
from colorlog import ColoredFormatter
from . import __version__
log = logging.getLogger(__name__)
@carlos-jenkins
carlos-jenkins / lookups.py
Created December 15, 2016 20:38
Python3 string index lookup vs bytes index lookup
from random import choice
from datetime import datetime
from string import ascii_letters, digits
def generate_string(length, choices=ascii_letters + digits):
return ''.join(choice(choices) for _ in range(length))
def compare_lookup(length):
@carlos-jenkins
carlos-jenkins / pybin2h.py
Created September 29, 2016 01:37
pybin2h is a tool for converting binary data to a C-style uchar array for compiling straight into C/C++ code written in Python 3.
#!/usr/bin/env python3
"""
pybin2h is a tool for converting binary data to a C-style uchar array for
compiling straight into C/C++ code written in Python 3.
"""
from itertools import islice
__version__ = '0.1.0'
@carlos-jenkins
carlos-jenkins / ifacegen.py
Created September 27, 2016 22:20
Small Software Packet Generator
from __future__ import division
from os.path import isfile
from json import dumps
from logging import getLogger
from traceback import format_exc
from base64 import b64encode, b64decode
from multiprocessing import Value, Queue, Event, Process
log = getLogger(__name__)
@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__)
@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 / 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 / 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
#