Skip to content

Instantly share code, notes, and snippets.

View fakuivan's full-sized avatar

fakuivan

  • Posadas, Misiones, Argentina
  • 21:31 (UTC -03:00)
View GitHub Profile
@fakuivan
fakuivan / Dockerfile.raspbian
Last active March 11, 2021 18:55
Dockerfile for building SeaDrive
FROM raspberrypi_os:latest as backend
RUN export DEBIAN_FRONTEND="noninteractive" && \
apt clean && apt update && \
apt install autoconf \
automake \
libtool \
libevent-dev \
libcurl4-openssl-dev \
libgtk2.0-dev \
@fakuivan
fakuivan / pdfpages.sh
Last active August 28, 2020 13:32
Bash function to get the number of pages in pdf files
pdfpages () {
if [[ $# -ne 1 ]]; then
echo "$FUNCNAME: expected one argument, got $#"
return 1
fi
local filename="$1"
while read line; do
if [[ "$line" =~ ^Pages:" "+([0-9]+)$ ]]; then
echo "${BASH_REMATCH[1]}"
return 0
@fakuivan
fakuivan / .bashrc
Last active June 23, 2021 19:52
Try to cd by swapping base by symlink
# Append this to your "~/.bashrc" file
if LINK="$(~/cdlink.sh ~/SeaDrive)"; then
cd "$LINK"
echo Changed base path to "${LINK@Q}"
fi
@fakuivan
fakuivan / sympyplot_tools.py
Created July 28, 2020 01:39
A collection of helpers for plotting using sympy
from typing import Iterator, Tuple, Dict, Any, Iterable, Union, cast
from sympy import plot as splot
from sympy.plotting.plot import Plot
from matplotlib import pyplot
from itertools import filterfalse
from more_itertools import unzip
import random
import colorsys
Curve = Tuple[Any, Dict[str, Any]]
@fakuivan
fakuivan / tasks.json
Last active July 19, 2020 01:10
vscode compile task for sourcepawn
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Compile plugins",
"type": "shell",
"command": "${config:sourcepawnLanguageServer.sourcemod_home}/../spcomp64",
"args": [
@fakuivan
fakuivan / reuse_guard.py
Last active July 7, 2020 21:20
Wraps an iterator so that StopIteration is only raised once
#!/usr/bin/env python3.8
from typing import TypeVar, Iterator
"""
https://docs.python.org/3/library/stdtypes.html#iterator-types
This is considered broken by the iterator protocol, however I think
that what's considered broken is to continue to _yield values_, where
with this we emphasize the fact that if ``StopIteration`` is raised
once, the iterator _should not be used_ further. Those are two
different things.
#!/usr/bin/env python3.8
from ipaddress import IPv6Network, IPv6Address
from typing import Optional, Tuple
from base64 import b32encode
# from https://github.com/zerotier/ZeroTierOne/blob/91b16310ea47a6de96edb488a61494f8ed8c139c/node/InetAddress.cpp#L427
def mk6plane(nwid: int, nodeid: int
) -> Tuple[IPv6Network, IPv6Network, IPv6Address]:
"""
Given a ZeroTier node and network ID, return
@fakuivan
fakuivan / json_finder.py
Last active December 13, 2022 15:22
Finds valid JSON strings in a file. Useful for reconstructing broken files or reverse engineering data structures in protocols or embedded into binaries
#!/usr/bin/env python3.8
# different from the re module (https://pypi.org/project/regex/ )
from ast import parse
from json import dumps
from typing import Any, List, NoReturn, TextIO, Tuple
import regex
import json
import sys
import argparse
@fakuivan
fakuivan / cron_helper.sh
Created June 1, 2020 03:02
cron is 💩
#!/bin/bash
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# https://stackoverflow.com/a/26827443
# shellcheck disable=SC2030,SC2034,SC2031
split_output() {
local -n array="$1" || return $?;
# shellcheck disable=SC1090
. <({
err="$({ out="$("${@:2}")"; ret=$?; } 2>&1;
@fakuivan
fakuivan / common.py
Last active May 16, 2020 16:50
Algunas resoluciones para los trabajos prácticos propuestos por la cátedra de la materia "Señales y Sistemas"
#!/usr/bin/env python3.8
from sympy import Basic, Piecewise, Symbol, Eq, Mod, Heaviside, sympify, plot as splot
import numpy
from typing import Hashable, Tuple, Iterable, NamedTuple, Callable, Type
from matplotlib import pyplot as mplot
from sympy.physics.units.definitions import Hz
from sympy.physics.units.quantities import Quantity
from sympy.physics.units.prefixes import kilo