Skip to content

Instantly share code, notes, and snippets.

View xrmx's full-sized avatar

Riccardo Magliocchetti xrmx

View GitHub Profile
@xrmx
xrmx / callable-typechecking.py
Last active February 11, 2021 10:33
Typechecking of callables stored in a dict
from typing import Callable, TypedDict
def string_ret() -> str:
return "string"
def int_ret() -> int:
return 1
class Func(TypedDict):
class BlogAdmin(admin.ModelAdmin):
list_display = ('__str__', 'get_num_comments')
def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.annotate(
num_comments=models.Count('comment')
)
def get_num_comments(self, obj):
@xrmx
xrmx / btrfs-chsheet.md
Created May 19, 2019 13:59 — forked from alter2000/btrfs-chsheet.md
Btrfs workshop OSCAL 2019

Hello there

I've prepared this in case I get sick or just too lazy to speak during the workshop, so that you won't be left high and dry.

If you've worked before with LVM/ZFS

Here's a table comparing terms:

Human Btrfs LVM ZFS

@xrmx
xrmx / gist:73b3d19e31637b08e8ba249c5d27e40d
Last active March 27, 2018 19:39
Descrizione demo del talk tenuto a MERGE-it 2018 https://speakerdeck.com/xrmx/superset-1
Come Demo vorrei farvi vedere quello che ha fatto napo in un suo post ma in modo diverso.
Come dati useremo sempre il dataset del Consip su Bandi e gare del 2017.
Che ho già scaricato qui. Ora per vedere cosa c'è dentro facciamo un head da terminale. Ah!
Ci sono problemi con gli accenti perchè evidentemente in Consip non è arrivato ancora unicode.
Per risolvere problemi di questo tipo la cosa più semplice è caricare il file in LibreOffice,
indovinare l'encoding (conviene scommettere su windows 1252) e riesportarlo in UTF-8.
Visto che ci siamo togliamo anche il commento nell'header che ci da solo fastidio.
Ora che abbiamo un csv utilizzabile andiamo direttamente su superset. Dalla versione 0.23 che
@xrmx
xrmx / 0_reuse_code.js
Created February 13, 2016 10:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@xrmx
xrmx / per_fare_un_lip
Created October 25, 2015 14:24
Cosa serve per fare un lip
Base:
- tavoli e sedie
- prolunghe elettriche
- ciabatte con eventuali adattatori shuko
- chiavette usb
@xrmx
xrmx / django-bootstrap3-tabular
Last active August 29, 2015 14:02
django-bootstrap3 tabular layout
from bootstrap3.renderers import FieldRenderer, FormsetRenderer
class ConcordiaFormsetRenderer(FormsetRenderer):
def render_form(self, form, **kwargs):
html = super(ConcordiaFormsetRenderer, self).render_form(form, **kwargs)
if self.layout == 'tabular':
return '<tr>{html}</tr>'.format(html=html)
return html
def render_form_labels(self):
@xrmx
xrmx / bingmatch.py
Last active January 1, 2016 09:39
So your hardisk died, you recovered your media files with photorec and bing could give you some hints about their content
import sys, re
import requests
"""
You need a microsoft account to use the bing search api, see http://datamarket.azure.com/dataset/bing/search
# It could make sense to query only for bigger files
find . -size +100M > Downloads.find
# get md5 digest
md5deep -f Downloads.find > Downloads.md5
@xrmx
xrmx / ocanvas-image-ie9.html
Last active December 31, 2015 17:49
ocanvas image ie9
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
--- static/js/bootstrap-datepicker.orig.js 2013-10-23 10:49:52.107728856 +0200
+++ static/js/bootstrap-datepicker.js 2013-10-23 12:04:45.769781994 +0200
@@ -43,6 +43,8 @@
this.isInput = this.element.is('input');
this.component = this.element.is('.date') ? this.element.find('.add-on, .btn') : false;
this.hasInput = this.component && this.element.find('input').length;
+ var altParent = this.element.offsetParent();
+ this.altParent = altParent.find('body').length ? false : altParent;
if(this.component && this.component.length === 0)
this.component = false;