Skip to content

Instantly share code, notes, and snippets.

View akiross's full-sized avatar
🥷
Ninja

Alessandro Re akiross

🥷
Ninja
View GitHub Profile
@akiross
akiross / asyncinit.py
Last active March 1, 2018 18:41
How to use async __init__ magic method in Python
import asyncio
class AsyncClass:
async def __new__(cls, *args, **kwargs):
o = super().__new__(cls)
# Explicit async call
await o.__init__(*args, **kwargs)
return o # __init__ will be called anyway
async def __init__(self, *args, **kwargs):
@akiross
akiross / img_selector.py
Last active May 18, 2018 10:24
Could be useful to let a human pick an image in a small set.
import cv2
import tkinter
from PIL import Image, ImageTk
def inter_evo(solutions, geometry=None, load=False, to_pil=False):
"""Ask user to select one image among the set.
Will open a window with some buttons and images over those buttons,
returns the index of the clicked image (button).
@akiross
akiross / checkboxes.html
Last active June 17, 2018 17:11
A collaborative checklist using SwellRT
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Collaborative checklist</title>
</head>
<body>
"""Given a root directory, search for Pipfiles in it and
produce the corresponding pipenv names.
This script can be useful to find lost project directories.
Python 3.6 is required (for f-strings).
This code is public domain.
"""
import os
import sys
@akiross
akiross / pipetest.py
Created October 15, 2018 13:53
A demo code to show what happens when pipe buffer get filled.
"""This code runs a subprocess that produces a large amount of data, while
the main process reads the data at a slower pace. What happens on the long run?
This program is a demo showing what happens when a pipe buffer gets filled.
"""
import io
import sys
import time
import textwrap
import tempfile
@akiross
akiross / dropbox_upload_large.py
Last active October 25, 2018 11:18 — forked from PetrGlad/dropbox_upload_large.py
Upload large files to dropbox
#!/usr/bin/env python3
# This tool helps uploading (large) files on your dropbox, without having to install it.
# First, be sure to create an app for this to run and generate a token:
# https://www.dropbox.com/developers/apps
# Setting up example
# $ python3 -m venv venv_dbx
# $ . ./venv_dbx/bin/activate
@akiross
akiross / sdl.go
Created November 1, 2018 14:17
sdl surface as drawable image
type Surface sdl.Surface
func (s *Surface) ColorModel() color.Model {
switch s.Format.Format {
case sdl.PIXELFORMAT_ARGB8888, sdl.PIXELFORMAT_ABGR8888:
return color.RGBAModel
case sdl.PIXELFORMAT_RGB888:
return color.RGBAModel
default:
@akiross
akiross / fedora_remote.md
Last active November 6, 2018 22:41
Remoting Fedoring

This is just a draft, I'm writing down few notes and I'll try to make this workable knowledge when I'll have actually tested it thoroughly.

Remote working with Fedora (among Fedora)

Assuming you got a decent version. I'm running F28, but F29 is out since a few days. With GNOME 3.30 you should have your life easier.

@akiross
akiross / file-hdf5.py
Created November 29, 2018 14:33
GIMP Python plugin to load and save HDF5 files
#!/usr/bin/env python2
#
# GIMP Plug-in for HDF5 files
# https://www.hdfgroup.org/solutions/hdf5/
#
# Copyright 2018 by Alessandro Re <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
@akiross
akiross / view_rotation.py
Created December 3, 2018 09:53
Plot rotation against x,y (similar to gnuplot surface rotation)
# This is a pseudocode tbh
def on_mouse_move(self, pos):
# Normalized distance of cursor motion
dist = (pos - self.last_mouse_pos) / (win_w, win_h)
# Build rotation matrices around
# y axis (when moving mouse horizontally)
rot_x = rotation_matrix(260 * dist.x(), 0, 1, 0)
# x axis (when moving mouse vertically)
rot_y = rotation_matrix(260 * dist.y(), 1, 0, 0)