Skip to content

Instantly share code, notes, and snippets.

View aleroddepaz's full-sized avatar

Alex Rodas aleroddepaz

  • Telefónica
  • Madrid, Spain
View GitHub Profile
@aleroddepaz
aleroddepaz / rgb2cie.py
Created April 5, 2013 12:40
Script to convert RGB color to CIE color space
import sys
def rgb_to_xy(r, g, b):
X = 0.412453 * r + 0.357580 * g + 0.180423 * b
Y = 0.212671 * r + 0.715160 * g + 0.072169 * b
Z = 0.019334 * r + 0.119193 * g + 0.950227 * b
x = X / (X+Y+Z)
y = Y / (X+Y+Z)
return x, y
@aleroddepaz
aleroddepaz / utils.py
Last active April 13, 2017 22:17
Collection of useful functions and patterns for Python
class Singleton(object):
"""
Decorator for the singletton pattern in Python: http://stackoverflow.com/q/31875
Usage::
>>> @Singleton
class MyClassSingleton(object): pass
>>> instance = MyClassSingleton.instance
@aleroddepaz
aleroddepaz / rename_songs.py
Last active December 16, 2015 04:39
Script to rename all the .mp3 files of a directory with a custom pattern. It uses the module eye3d. To find more information about it, check http://eyed3.nicfit.net/
import os
import re
import sys
import eyed3
def rename_songs(path, pattern):
if not check_arguments(path, pattern):
exit(1)
listdir = [os.path.join(path, f) for f in os.listdir(path)]
files = filter(os.path.isfile, listdir)
@aleroddepaz
aleroddepaz / httpguiclient.py
Created May 3, 2013 02:28
HTTP GUI client written in Python, using the standard modules `Tkinter` and `urllib2`.
from Tkinter import *
import urllib2
HTTP_METHODS = ["GET", "POST", "PUT", "REMOVE"]
class HttpGuiApplication(Tk):
def __init__(self):
Tk.__init__(self)
@aleroddepaz
aleroddepaz / ftpuploader.py
Last active March 12, 2023 17:17
Script for uploading a directory and its subdirectories to a FTP server
#!/usr/bin/env python
import sys
import os
import ftplib
import socket
import getpass
try:
input = raw_input
@aleroddepaz
aleroddepaz / md5sum.py
Created June 11, 2013 23:49
Script to verify data integrity using the MD5 hash.
import sys
import hashlib
from functools import partial
def md5sum(filename):
with open(filename, mode="rb") as f:
md5 = hashlib.md5()
buf_size = md5.block_size * 64
for buf in iter(partial(f.read, buf_size), b''):
@aleroddepaz
aleroddepaz / music2time.py
Created June 15, 2013 19:48
Script to keep track of keydown events during playing music.
import pygame
import time
import sys
def main(ogg_file, output_file):
pygame.display.init()
pygame.display.set_mode((100, 100))
pygame.mixer.init()
pygame.mixer.music.load(ogg_file)
f = open(output_file, 'w')
@aleroddepaz
aleroddepaz / canvas2pdf.py
Last active February 9, 2024 21:02
Proof of concept: How to export the content of a Tkinter Canvas to a PDF with ghostscript.
"""
Setup for Ghostscript:
Download it from http://www.ghostscript.com/ and
add `/path/to/gs9.07/bin/` and `/path/to/gs9.07/lib/` to your path.
"""
import os
import subprocess
import tkinter as tk
@aleroddepaz
aleroddepaz / HelloWorld.java
Created March 3, 2014 21:10
JavaFX example application
public class HelloWorld extends Application {
private Calculator calculatorService;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws MalformedURLException {
@aleroddepaz
aleroddepaz / pure-js-treeview.html
Last active August 29, 2015 14:25
Pure JS Treeview, based on nested unordered lists
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<style>
.treeview ul {
padding-left: 24px;
list-style-type: none;
}
.treeview li > div {