Skip to content

Instantly share code, notes, and snippets.

@vanzaj
vanzaj / rnd_gen.py
Last active December 15, 2015 22:49
helper functions to generate random data
import random
import string
import datetime
def resample(lst, n):
''' return a list of length n of randomly chosen elements
from an input list'''
inp = list(lst)
if n <= 0:
@vanzaj
vanzaj / log2file.py
Last active December 18, 2015 19:08
logging example with syslog like formatting
import logging
import logging.handlers
LOG_FILE = 'test.log'
#logging.basicConfig(filename=LOG_FILE,
#level=logging.DEBUG,
#)
#logging.debug('this should be in the log file')
from datetime import datetime
now = datetime.now()
codes = [
r'%Y-%m-%d %H:%M:%S',
r'%a %b %d %H:%M:%S',
r'%A %B %d',
r'%c',
r'%x %X %z %Z', # locale's date & time, UTC offset and timezone
@vanzaj
vanzaj / try_pypdf2.py
Created June 27, 2013 09:42
testing PyPDF2
import sys
from pathlib import Path
# add local (unpiped) PyPDF2
p = Path(str(__file__)).absolute().parent(level=2)
sys.path.append(p.join('dld', 'PyPDF2').as_posix())
from PyPDF2 import PdfFileReader
from PyPDF2 import PdfFileWriter
import yaml
document = """
a: 1
b:
- 0.5
- one
- True
c:
key: 3
@vanzaj
vanzaj / into-to-python
Created August 23, 2013 07:07
Quick introduction to Python using IPython Notebook
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@vanzaj
vanzaj / time_str_contact
Last active December 22, 2015 15:19
timing of str concat in python
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@vanzaj
vanzaj / practical_analytics_ipynb
Created November 19, 2013 01:53
Practical data analytics with Python
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@vanzaj
vanzaj / pm_crypto.py
Created January 7, 2014 01:32
poor man crypto
# poor man crypto
import base64
def _shiftchars(s):
lens = len(s)
if lens == 1:
return s
elif lens == 2:
return s[1]+s[0]
else:
@vanzaj
vanzaj / openvpn.sh
Created February 8, 2014 07:52
openvpn_setup.sh
#!/bin/sh
# source: https://github.com/tinfoil/openvpn_autoconfig/blob/master/bin/openvpn.sh
set -e
apt-get update -q
apt-get install -qy openvpn curl
cd /etc/openvpn
[ -f dh.pem ] || openssl dhparam -out dh.pem 2048