Skip to content

Instantly share code, notes, and snippets.

View rshk's full-sized avatar
😎
Being awesome

Samuele Santi rshk

😎
Being awesome
  • Tampa, Florida
View GitHub Profile
% py.test -vvv test_py2_logging.py
================================================================================================================================================== test session starts ===================================================================================================================================================
platform linux2 -- Python 2.7.11, pytest-2.9.0, py-1.4.31, pluggy-0.3.1 -- /tmp/tmp.x9LSkBqfG8/.venv2.7/bin/python2.7
cachedir: .cache
rootdir: /tmp/tmp.x9LSkBqfG8, inifile:
collected 4 items
test_py2_logging.py::test_logging_bytes_to_bytes PASSED
test_py2_logging.py::test_logging_unicode_to_bytes PASSED
test_py2_logging.py::test_logging_bytes_to_unicode PASSED
In [1]: from schema_object import SchemaObject
In [2]: class Person(SchemaObject):
...: first_name = None
...: last_name = None
...: email = None
...:
In [3]: Person()
Out[3]: Person()
import subprocess
import sys
flake8 = ['flake8'] + sys.argv[1:]
proc = subprocess.Popen(flake8, stdout=subprocess.PIPE)
for line in proc.stdout:
filename, row, col, extra = [
x.strip().decode('utf8')

Assisted CHANGELOG entries creation

This should be usable for getting log messages of changes not already described in the CHANGELOG.. handy for remembering what needs to be documented.

git log "$( git --no-pager log -n1 --pretty='format:%H' -- ./CHANGELOG ).."
AWS_SECRET_KEY: x'; DROP TABLE aws_keys; --
@rshk
rshk / HTTP response
Last active August 29, 2015 14:08
jQuery XHR "weird" behavior
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Cache-Control: public, max-age=30
Connection: keep-alive
Content-Length: 320
Content-Type: application/json
Date: Mon, 27 Oct 2014 10:52:06 GMT
Server: gunicorn/18.0
@rshk
rshk / create-vm.ps1
Created July 29, 2014 15:49
PowerShell Create VM
# ------------------------------------------------------------
# Create Hyper-V virtual machine via PowerShell
# ------------------------------------------------------------
# Variables
$VM_NAME = "PS_TEST_VM"
$VM_MAC = "00:15:5d:11:22:01"
$VM_RAM = 256GB
$VM_CPUS = 16
@rshk
rshk / cli-progress.py
Created June 5, 2014 15:05
Python CLI progress bar
import time
for i in xrange(101):
print("\033[1A\033[K[{0}{1}] {2}%".format('=' * i, ' ' * (100 - i), i))
time.sleep(.05)
@rshk
rshk / kibana-apache-logs.json
Created May 6, 2014 16:16
Kibana: analyze Apache logs
{
"title": "Apache logs",
"services": {
"query": {
"list": {
"0": {
"query": "*",
"alias": "",
"color": "#7EB26D",
"id": 0,
@rshk
rshk / README.md
Last active May 20, 2018 04:07
Python colorful logging example

Usage example

% python -i colorful_logging_formatter.py 
>>> import logging
>>> logger = logging.getLogger('foo')
>>> logger.setLevel(logging.DEBUG)
>>> import sys
>>> handler = logging.StreamHandler(sys.stderr)
>>> handler.setFormatter(ColorLogFormatter())