Skip to content

Instantly share code, notes, and snippets.

View sigilioso's full-sized avatar

Christian sigilioso

View GitHub Profile
@sigilioso
sigilioso / cuter.py
Created June 19, 2012 22:58
Python PIL Example: get a thumbnail by resizing and cropping an image.
# -*- coding: utf-8 -*-
import Image
def resize_and_crop(img_path, modified_path, size, crop_type='top'):
"""
Resize and crop an image to fit the specified size.
args:
img_path: path for the image to resize.
@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 / .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 / 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 / .bashrc
Last active April 19, 2018 07:17
Custom prompt including git information
export LANGUAGE==en_US.utf8
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
source ~/.utils/git-completion.bash
# Only if docker installed
source /etc/bash_completion.d/docker
@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
@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 / input_help_validation.html
Created October 2, 2012 22:44
jQuery simple input help to choose a correct value.
<html>
<head>
<style>
.input_error {
color: red;
font-weight: bold;
}
#code_value_error {
color: red;
}