Skip to content

Instantly share code, notes, and snippets.

@antzucaro
antzucaro / tuning_server_top_scorers.md
Created March 14, 2021 18:37
Query Tuning - Top Scorers by Server ID

Server "top scorers" query

The original query in Python, using the ORM:

top_scorers_q = DBSession.query(
    fg.row_number().over(
        order_by=expr.desc(func.sum(PlayerGameStat.score))).label("rank"),
    Player.player_id, Player.nick,
    func.sum(PlayerGameStat.score).label("total_score"))\
/*
This yeields the following:
12 bytes written
<nil>
could not decode data
*/
@antzucaro
antzucaro / rtmp.go
Created October 14, 2018 01:08
RTMP XML parser and HTTP stub
package main
import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
)
@antzucaro
antzucaro / strip_xonotic_low.txt
Created March 1, 2018 13:31
Remove unnecessary files from a Xonotic "low" build.
user@host:% tree autobuild/
autobuild/
├── data
│ ├── xonotic-rsync-data-low.pk3
│ └── xonotic-rsync-maps-low.pk3
├── key_0.d0pk
└── xonotic-linux64-dedicated
1 directory, 4 files
@antzucaro
antzucaro / blogofile_convert.go
Created March 2, 2014 03:58
Blogofile conversion
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"
"strconv"
"time"
@antzucaro
antzucaro / steps.txt
Created January 1, 2014 22:42
Pulls listened tracks from a given user's Last.fm account between the provided time bounds, dumping the results to a file "tracks.csv". Usage: go run summarizr.go -user <username> -key <Last.fm API key> -from <Unix timestamp> -to <Unix timestamp>
Generate the data (timestamps represent the entirety of 2013):
go run summarizr.go -user antzucaro -key MY_API_KEY -from 1357016400 -to 1388552340
This produces a file "tracks.csv" with the selected range of data (8173 songs in total for me). One can load these tracks to a database easily with the below steps.
Create the database:
postgres=# create database tracks2013 encoding='utf-8';
CREATE DATABASE
@antzucaro
antzucaro / elo.py
Created July 26, 2012 11:47
Blended Elo - for non-duel games, use the real scorefactor for S. For duels, use 1, 0, and 0.5.
from pyramid.paster import bootstrap
from xonstat.elo import *
from xonstat.models import *
def process_elos(game, session, game_type_cd=None):
if game_type_cd is None:
game_type_cd = game.game_type_cd
# we do not have the actual duration of the game, so use the
# maximum alivetime of the players instead
#!/bin/sh
# this bit came from youtube.com/watch?v=_XDa1ahl7fw
INFO=$(xwininfo)
WIN_GEO=$(echo $INFO | grep -oEe 'geometry [0-9]+x[0-9]+' | grep -oEe '[0-9]+x[0-9]+')
WIN_XY=$(echo $INFO | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' | grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/\+/,/' )
AUDIO_INPUT="-f alsa -i hw:0,0 -ac 2"
VIDEO_INPUT="-f x11grab -r 30 -s $WIN_GEO -i :0.0+$WIN_XY"
#AUDIO_CODEC="-acodec pcm_s16le"
@antzucaro
antzucaro / img_util.py
Created September 30, 2011 17:23
Rename images according to their creation time.
import sys
from glob import glob
from os import stat, rename
from os.path import splitext
from PIL import Image
from PIL.ExifTags import TAGS
from pyexif import ExifEditor
from time import strptime, mktime
# does not work as of 9/22/2011 - exception on _getexif() below
@antzucaro
antzucaro / new_post.py
Created March 3, 2011 19:09
Command line utility to create new blogofile posts. Expects to be in the blogofile root directory.
#!/usr/bin/python
import os
import re
import sys
from optparse import OptionParser
from datetime import datetime
def sluggify(text=None):
text = re.sub(r'[?:\'!@#$%^&*()+=]', '', text)