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 / 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 / persistence.xml
Last active June 28, 2023 17:54
Sample JPA 2.1 persistence units
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<!-- Hibernate + H2 -->
<persistence-unit name="standalonePu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.acme.MyEntity</class>
<properties>
@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 / tk_asyncio.py
Created August 26, 2021 19:14
Tkinter and asyncio proof of concept
import asyncio
import tkinter as tk
# Concepts
# https://www.tcl.tk/man/tcl8.7/TkLib/MainLoop.html
# https://www.tcl.tk/man/tcl8.7/TclLib/DoOneEvent.html
# https://www.tcl.tk/man/tcl8.7/TclCmd/update.html
# https://www.tcl.tk/man/tcl8.7/TclCmd/after.html
# SO related questions
@aleroddepaz
aleroddepaz / pyheartbeat_client.py
Created August 26, 2021 19:12
PyHeartBeat example
import sys
import time
import socket
import asyncio
DEFAULT_IP = '127.0.0.1' # local host, just for testing
DEFAULT_PORT = 43278 # an arbitrary UDP port
BEATWAIT = 1 # number of seconds between heartbeats
async def main():
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Event delegation example (with jQuery)</title>
<style>
button { margin: 5px; }
</style>
</head>
<body>
@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 / 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 / counter.html
Last active April 13, 2017 21:22
ES6 class for a counter widget
<!DOCTYPE html>
<html>
<head>
<title>Hello, ES6</title>
<script src="counter.js"></script>
</head>
<body>
<my-counter></my-counter>
</body>
</html>
@aleroddepaz
aleroddepaz / flex.html
Created November 10, 2016 21:58
Flexbox navigation menu
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Flex navigation menu</title>
<style>
body {
font-family: sans-serif;
margin: 0;
}