Skip to content

Instantly share code, notes, and snippets.

@pshchelo
pshchelo / gs2cbz.py
Last active December 19, 2015 21:49
Convert a PDF or PS files to CBZ files via Ghostscript
#!/usr/bin/env python
'''Convert PDF or PS files to CBZ files
CBZ files are ZIP-compressed sets of image files, this script in particular creates PNG images
it takes filename and target resolution (DPI) as arguments
'''
import os, sys
import getopt, shutil
@pshchelo
pshchelo / git-mail-change.sh
Last active December 27, 2015 04:09
change git author emails by REWRITING HISTORY
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_EMAIL" = "WRONG_EMAIL" ];
then
GIT_COMMITTER_EMAIL="NEW_EMAIL";
GIT_AUTHOR_EMAIL="NEW_EMAIL";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD
# Assert misuses in tests:
# bug/1259023 - assertIs/assertIsNone - MERGED 1/2
ack "assert((Not)*Equal)\(.*(None|True|False).*\)"
# bug/1259292 - assertEqual (order of args) - inspect manually
ack "assertEqual\((.*)\)"
# bug/1259941 - assertIsInstance - MERGED
ack "assert((True|False)\(.*isinstance\(.*\).*\))|((Not)*(Equal)\(.*type\(.+\).*\))"
@pshchelo
pshchelo / post-merge
Last active April 17, 2021 23:54 — forked from sindresorhus/post-merge
Git hook to auto-update pytnon venv after `git pull` if some certain files were changed
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# Forked by Pavlo Shchelokovskyy (pshchelo) - pshchelo.bitbucket.org
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
@pshchelo
pshchelo / sahara-sg.py
Last active August 29, 2015 14:09
Sahara Nova network security group rules
import os
from novaclient import client
private_cidr = '10.0.0.1/24'
private_ports = [8020, 8021, 8030, 8031, 8032, 8033, 8040, 8041, 8042, 8088,
9000, 10020, 19888, 50010, 50020]
public_cidr = '0.0.0.0/0'
public_ports = [22, 80, 8080, 11000, 50030, 50060, 50070, 50075, 50090]
@pshchelo
pshchelo / tilt
Created March 25, 2015 14:49
Using accelerometer to change desktop workspace by tilting the notebook
#!/usr/bin/python
import time
import os
with open('/sys/devices/platform/lis3lv02d/position','r') as f:
for i in xrange(100):
f.seek(0)
data = f.read()
x, y, z = map(int, data.strip()[1:-1].split(','))
print "{:d}\t{:d}\t{:d}".format(x, y, z)
if y > 200:
@pshchelo
pshchelo / mp3-neroaac.sh
Created April 12, 2015 09:32
cli transcode mp3 to aac with NeroAAC
for f in *.mp3
do
OUTF=`echo "$f" | sed s/\.mp3$/.aac/g`
ARTIST=`ID3 "$f" --show-tag=GENRE| sed s/.*=//g`
TITLE=`ID3 "$f" --show-tag=GENRE| sed s/.*=//g`
ALBUM=`ID3 "$f" --show-tag=GENRE| sed s/.*=//g`
GENRE=`ID3 "$f" --show-tag=GENRE | sed s/.*=//g`
@pshchelo
pshchelo / mount-qcow2-lvm-image.sh
Last active March 6, 2024 19:05
List of commands to mount/unmount a qcow2 image conatining LVM partitions.
# kudos to dzaku at consolechars.wordpress.com
### MOUNT qcow2 image with lvm partitions
# ensure nbd can handle that many partitions
sudo modprobe nbd max_part=8
# present image as block device through NBD
sudo qemu-nbd --connect=/dev/nbd0 <image.qcow2>
@pshchelo
pshchelo / team-stats.py
Last active April 19, 2017 10:17
Stackalytics stats fetcher
#!/usr/bin/env python
import calendar
import datetime
import time
import requests
from six.moves.urllib import parse as urlparse
TEAM = [
@pshchelo
pshchelo / allmacs.py
Last active November 2, 2016 11:43
all macs
#!/usr/bin/env python
"""Return all non-zero Ethernet (6 octets) MAC addresses"""
import itertools
import re
import netifaces
MAC_REGEXP = re.compile("^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$")