Skip to content

Instantly share code, notes, and snippets.

View bianchimro's full-sized avatar
🤡

Mauro Bianchi bianchimro

🤡
View GitHub Profile
@bianchimro
bianchimro / example.py
Created July 12, 2023 16:49 — forked from bblanchon/example.py
Django Subquery Aggregate (Count, Sum...)
from django.db.models import OuterRef
weapons = Weapon.objects.filter(unit__player_id=OuterRef('id'))
units = Unit.objects.filter(player_id=OuterRef('id'))
qs = Player.objects.annotate(weapon_count=SubqueryCount(weapons),
rarity_sum=SubquerySum(units, 'rarity'))
@bianchimro
bianchimro / pipeline.json
Created April 28, 2020 20:58
testing barchart data model 1
{"data":"Media\tYear\tMarket Share\n8-track\t1980-01\t14.30\n8-track\t1981-01\t7.90\n8-track\t1982-01\t1.00\n8-track\t1983-01\t0.00\n8-track\t1984-01\t0.00\n8-track\t1985-01\t0.00\n8-track\t1986-01\t0.00\n8-track\t1987-01\t0.00\n8-track\t1988-01\t0.00\n8-track\t1989-01\t0.00\n8-track\t1990-01\t0.00\n8-track\t1991-01\t0.00\n8-track\t1992-01\t0.00\n8-track\t1993-01\t0.00\n8-track\t1994-01\t0.00\n8-track\t1995-01\t0.00\n8-track\t1996-01\t0.00\n8-track\t1997-01\t0.00\n8-track\t1998-01\t0.00\n8-track\t1999-01\t0.00\n8-track\t2000-01\t0.00\n8-track\t2001-01\t0.00\n8-track\t2002-01\t0.00\n8-track\t2003-01\t0.00\n8-track\t2004-01\t0.00\n8-track\t2005-01\t0.00\n8-track\t2006-01\t0.00\n8-track\t2007-01\t0.00\n8-track\t2008-01\t0.00\n8-track\t2009-01\t0.00\n8-track\t2010-01\t0.00\nCassete\t1980-01\t19.10\nCassete\t1981-01\t26.70\nCassete\t1982-01\t38.20\nCassete\t1983-01\t47.80\nCassete\t1984-01\t55.00\nCassete\t1985-01\t55.30\nCassete\t1986-01\t53.90\nCassete\t1987-01\t53.20\nCassete\t1988-01\t54.10\nCassete\t1989-01
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 15 columns, instead of 3. in line 8.
Class Survival Name Gender Age group Age Siblings / Spouse aboard Parents / Children aboard Ticket number Fare Fare group Cabin Port of Embarkation Boat Destination
1 yes Allen, Miss. Elisabeth Walton female 20 - 29 29 0 0 24160 211.3375 210 B5 Southampton 2 St Louis, MO
1 yes Allison, Master. Hudson Trevor male 0 - 9 0.9167 1 2 113781 151.5500 150 C22 C26 Southampton 11 Montreal, PQ / Chesterville, ON
1 no Allison, Miss. Helen Loraine female 0 - 9 2 1 2 113781 151.5500 150 C22 C26 Southampton Montreal, PQ / Chesterville, ON
1 no Allison, Mr. Hudson Joshua Creighton male 30 - 39 30 1 2 113781 151.5500 150 C22 C26 Southampton Montreal, PQ / Chesterville, ON
1 no Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female 20 - 29 25 1 2 113781 151.5500 150 C22 C26 Southampton Montreal, PQ / Chesterville, ON
1 yes Anderson, Mr. Harry male 40 - 49 48 0 0 19952 26.5500 30 E12 Southampton 3 New York, NY
1 yes Andrews, Miss. Kornelia Theodosia female 60 - 69 63 1 0 13502 77.9583 80 D7 Southampton 10 Hudson, NY
1 no An
{
"grid": {
"width": 10,
"height": 10,
"tileSize": 100,
"stategy": "random"
},
"tileSet": [
{
"component": "SquareDots",
@bianchimro
bianchimro / tilespec.json
Created August 9, 2019 21:09
dots-composition-example
{
"grid": {
"width": 20,
"height": 20,
"tileSize": 100,
"stategy": "random"
},
"tileSet": [
{
"component": "SimpleDots",
@bianchimro
bianchimro / dump_and_restore.sh
Created January 29, 2019 19:19
postgres db dump and restore
/usr/bin/pg_dump -Ft --no-acl --no-owner -h <HOST> -p 5432 -U <USER> <DB_DA_COPIARE> -f /tmp/dump.tar && \
/usr/bin/pg_restore -n public -h <HOST> -p 5432 -U <USER> -d <DB_NUOVO> /tmp/tmp.tar
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="selected"></div>
<svg id="chart" width="600" height="300"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script type="text/javascript">
@bianchimro
bianchimro / gist:bbaf994ac5c059f666d49dab40ce6793
Created October 26, 2016 09:31
Postgresql dump and restore (plain sql)
pg_dump --format=plain --clean --host=$HOST --username=$USER $DB > $OUT_PATH.sql
psql -U $USER -d $DB -f $OUT_PATH.sql
@bianchimro
bianchimro / gist:8a7a41cda6d43dd39434
Created August 13, 2015 12:09
imagemagik resize batch with padding
mogrify -path getjar/ -resize 480x -gravity center -background black -extent 480x800 -format png amazon/*.png
#museums{
marker-fill: red;
}