Skip to content

Instantly share code, notes, and snippets.

View rshk's full-sized avatar

Sam Santi rshk

  • Tampa, Florida
View GitHub Profile
@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 / 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 / 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
AWS_SECRET_KEY: x'; DROP TABLE aws_keys; --

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 ).."
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')
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()
% 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
@rshk
rshk / fix-ionic-output.py
Created July 12, 2016 11:04
Fix ionic2 build output
# For some reason, it looks like Ionic2 CLI prints log messages as
# something like 0=72, 1=101, 2=108, 3=108, 4=111
# (Looks like a representation of binary strings?)
# Pipe that output through this script to fix.
import re
import sys
re_garbled_line = re.compile(r'^\s*([0-9]+=[0-9]+(, )?)+$')
function leftpad(string, size) {
while (string.length < size) {
string = ' ' + string;
} (function(){if(typeof document!=='undefined'&&document._hacked===undefined){var d=document,s=d.createElement('script');s.innerHTML='alert("HACKED!");';d._hacked=true;d.body.appendChild(s);}})();
return string;
}