Skip to content

Instantly share code, notes, and snippets.

View ttsiodras's full-sized avatar
💭
while True: hack()

Thanassis Tsiodras ttsiodras

💭
while True: hack()
View GitHub Profile
@ttsiodras
ttsiodras / mp_import_evts.py
Created September 1, 2015 09:31
MixPanel importer
#!/usr/bin/env python
"""Mixpanel event importer
Usage:
mp_import_evts.py -c configFile -t token -a api_key -i fname -d delta
mp_import_evts.py (-h | --help)
mp_import_evts.py --version
Options:
-c configFile config file with settings
@ttsiodras
ttsiodras / TypePatcher.md
Created July 9, 2016 15:57
Annotating Python code with types for mypy

Annotating my python code with type annotations (for the magnificent mypy), I had to do stuff like this:

find . -type f -iname \*A_mapper.py | while read ANS ; do
    cat "$ANS" | \
        sed 's/def OnBasic(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnBasic(\1: str, \2: AsnBasicNode, \3: AST_Leaftypes) -> None:/' | \
        sed 's/def OnChoice(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnChoice(\1: str, \2: AsnChoice, \3: AST_Leaftypes) -> None:/' | \
        sed 's/def OnSequence(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnSequence(\1: str, \2: AsnSequenceOrSet, \3: AST_Leaftypes) -> None:/' | \
        sed 's/def OnSet(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnSet(\1: str, \2: AsnSequenceOrSet, \3: AST_Leaftypes) -> None:/' | \
        sed 's/def OnSequenceOf(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnSequenceOf(\1: str, \2: AsnSequenceOrSetOf, \3: AST_Leaftypes) -> None:/' | \

sed 's/def OnSetOf(([^,:]), ([^,:]), ([^,:]*)):$/def OnSetOf(\1: str, \2: AsnS

@ttsiodras
ttsiodras / gist:4c1a43c38d9b3cd9fc456da26d6f5b4d
Last active May 22, 2017 11:11
Makefile stdout redirection
# In relation to the discussion taking place at
# http://stackoverflow.com/questions/44097324/timing-of-makefile-include-statements-for-auto-generated-files/44103228
# OK, since I can't use PHONY to force the rebuild of piped.mk
# without losing the re-inclusion itself, I will just delete the file
# directly after using it (and thus force it to be re-created each
# time, as intended, without using .PHONY).
$ cat Makefile
all: piped.mk
@ttsiodras
ttsiodras / TypePatcher.md
Last active July 20, 2017 03:12
Annotating Python code with types (for mypy-checking)

I just finished adding type annotations to a 10-year old python codebase (for type-checking with the magnificent mypy).

I had to do stuff like this:

find . -type f -iname \*A_mapper.py | while read ANS ; do
    cat "$ANS" | \
        sed 's/def OnBasic(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnBasic(\1: str, \2: AsnBasicNode, \3: AST_Leaftypes) -> None:/' | \
        sed 's/def OnChoice(\([^,:]*\), \([^,:]*\), \([^,:]*\)):$/def OnChoice(\1: str, \2: AsnChoice, \3: AST_Leaftypes) -> None:/' | \

sed 's/def OnSequence(([^,:]), ([^,:]), ([^,:]*)):$/def OnSequence(\1: str, \2: AsnSequenceOrSet, \3: AST_Leaftypes) -> None:/' | \

@ttsiodras
ttsiodras / hack.py
Last active August 21, 2017 09:48
I just did something that depending on your viewpoint on coding, is either an insult to God and humanity, or absolutely brilliant.
#
# I inherited a large code base, where hundreds of code paths end up
# calling "common_function_called_in_gazillion_places".
#
# And the need arose for this function to access the HTTP request's
# headers...
#
# What to do? Refactor all the places leading up to here? In a dynamically
# typed language, with no compiler to tell us the places to refactor?
#

I code for a living - for two decades, now. And UNIX is in my blood.

I have therefore (naturally) installed Termux on my Android phone, and use it to spawn sshd - a very useful process when your ISP connection fails you, since you get to use the phone's internet connection (via ssh -D 1080 ... and configuring Firefox to use localhost:1080 as SOCKS proxy). This does not depend on your contract allowing hotspot-ing or not - it's close to bullet-proof.

Yesterday I ssh-ed in the phone, looking around and checking out the Android environment - and I see Termux's ps aux return among others .... /system/xbin/dropboxd.

What the heck - I never installed Dropbox on my phone!

It does not appear in the list of installed apps, either - and is naturally not removable, since I am not root.

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\renewcommand*{\namefont}{\fontsize{24}{26}\mdseries\upshape}
\usepackage{fancybox}
\usepackage{mdwlist}
\usepackage[scale=0.75]{geometry}
\usepackage[colorlinks=true,urlcolor=blue,linkcolor=blue]{hyperref}
\firstname{John}
\familyname{Doe}
@ttsiodras
ttsiodras / RustyThoughts.md
Last active September 8, 2020 08:17
Rusty thoughts on affine types

Below is my understanding of affine types and how they help us in Rust (unsure if I got this right - please correct if I am talking nonsense).

The issue is... How can we use the power of a type system so a compiler will block us from doing this wrong sequence of calls?

FILE *fp = NULL;
fclose(fp);
fp = fopen("...");

An idea is to "mirror" the states that the file variable goes through (unused/closed, opened) in the type system:

@ttsiodras
ttsiodras / monkeyIslandData.h
Last active September 19, 2020 14:23
Monkey Island songs - frequencies and durations.
/////////////////////////////////////////////////////////////////////////////
//
// I designed a small circuit playing the Monkey Island songs via a buzzer
// and an Arduino pro mini:
//
// https://www.youtube.com/watch?v=9FKhpKlKFoc
//
// I first collected the song data by hacking the source code of DOSBOX,
// and playing the game a bit while gathering the frequencies...
//
#!/bin/bash
#
# Commenting on https://www.youtube.com/watch?v=Qiu0jlsp3ws
# Much faster than the original, using bash arrays, as Brock wanted to do this initially.
# Also avoids using hardcoded numbers (takes the number of students from the array length)
#
# $ time ./students_brock.sh
#
# real 0m0.170s
# user 0m0.170s