Skip to content

Instantly share code, notes, and snippets.

View sigilioso's full-sized avatar

Christian sigilioso

View GitHub Profile
@sigilioso
sigilioso / set_date.py
Created February 4, 2023 19:42
Set creation date for a set of pictures (one second date difference)
# -*- coding: utf-8 -*-
from glob import glob
from exiftool import ExifToolHelper
from datetime import datetime
from datetime import timedelta
# Requires exiftool and pyexiftool. See: <https://sylikc.github.io/pyexiftool/installation.html#pyexiftool-dependencies>
photos = sorted(glob('**/*.jpg'))
@sigilioso
sigilioso / xor.py
Created May 31, 2018 06:54
Simple XOR encrypt/decrypt
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
from binascii import unhexlify, hexlify
from itertools import cycle
def encrypt(data, key):
return hexlify(bytes(x ^ y for x, y in zip(bytes(data, "utf-8"), cycle(unhexlify(key)))))
@sigilioso
sigilioso / postactivate
Created November 25, 2015 11:00
Environment variables for python virtualenvs with virtualenvwrapper
#!/bin/bash
# This hook is run after this virtualenv is activated.
# To be in $VIRTUALENV_HOME/bin/postactivate
if [[ -n $DJANGO_SETTINGS_MODULE ]]
then
export DJANGO_SETTINGS_MODULE_BACKUP=$DJANGO_SETTINGS_MODULE
fi
export DJANGO_SETTINGS_MODULE=YOUR.VALUE
@sigilioso
sigilioso / property_mock_example.py
Created November 26, 2014 10:15
Side effect for mocks on object attributes access.
from unittest import TestCase
import mock
from django import models
from django.core.exceptions import ObjectDoesNotExist
class Foo(models.Model):
# ...
@property
def has_pending_related(self):
try:
@sigilioso
sigilioso / psql_tmpfs.sh
Last active August 29, 2015 14:04
Posgresql in memory for testing
#!/bin/bash
set -x
service postgresql stop
TMPDIR=/tmp/tmp_psql
MOUNTPOINT=/var/lib/postgresql
mount -t tmpfs -o size=512M,nr_inodes=10k,mode=0777 tmpfs $TMPDIR
rsync --archive $MOUNTPOINT/ $TMPDIR/
mount -o bind $TMPDIR $MOUNTPOINT
service postgresql start
@sigilioso
sigilioso / xunit_summary.py
Created July 28, 2014 12:29
Parses xunit xml output and shows it in a 'human-readable' way.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import glob
from lxml import etree
def tests_elements(nodes):
for elm in nodes:
@sigilioso
sigilioso / .gitconfig
Last active February 7, 2019 09:35
gitconfig
[user]
name = Your Name
email = mail@domain.com
[color]
ui = true
[pull]
default = current
[push]
default = current
[alias]
@sigilioso
sigilioso / pre_commit_python.py
Last active December 24, 2015 23:29
Git pre-commit: python. Look for debugger traces, check flake8 on changed code and run unit-test via external script.
#!/usr/bin/env python
import os
import sys
import re
import subprocess
from functools import partial
# Fabric requirement just for easy colour output
from fabric.colors import red, green, yellow
@sigilioso
sigilioso / asserts_picker.py
Last active December 21, 2015 01:39
An example to provide assert function from unittest.TestCase
from unittest import TestCase
import inspect
class AssertExample(object):
def __create_method(self, tc, name):
def method(self, *args, **kwargs):
return tc.__getattribute__(name)(self, *args, **kwargs)
return method
@sigilioso
sigilioso / post-checkout.sh
Last active December 11, 2015 20:19
post-checkout hook to remove old pyc files and avoid errors
# post-checkout hook (on <path-to-project>/.git/hooks/post-checkout file)
# to avoid errors for old pyc files when checkout.
# Remember execution privileges (chmod +x <path-to-project>/.git/hooks/post-checkout).
#!/bin/bash
# Start from the repository root
cd ./$(git rev-parse --show-cdup)
# Delete pyc and empty directories
echo "[post-checkout] Deleting .pyc and empty directories"
find . -name "*.pyc" -delete