Skip to content

Instantly share code, notes, and snippets.

Avatar

fakuivan

  • Posadas, Misiones, Argentina
View GitHub Profile
@fakuivan
fakuivan / pdfpages.sh
Last active Aug 28, 2020
Bash function to get the number of pages in pdf files
View pdfpages.sh
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
Created Aug 24, 2020
Try to cd by swapping base by symlink
View .bashrc
# Try to cd by swapping base by symlink
cdlink () {
local relative
local base="$1"
relative=$(realpath --relative-to="$base" .) &&
cd "$base/$relative" &&
return 1 # Not sure how to check this was successful
}
declare -a HOME_SYMLINKS=( "/mnt/c/Users/fakui/Seafile" )
@fakuivan
fakuivan / sympyplot_tools.py
Created Jul 28, 2020
A collection of helpers for plotting using sympy
View sympyplot_tools.py
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 Jul 19, 2020
vscode compile task for sourcepawn
View tasks.json
{
// 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 Jul 7, 2020
Wraps an iterator so that StopIteration is only raised once
View reuse_guard.py
#!/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.
View zerotier_info.py
#!/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 Jun 11, 2020
Finds valid JSON strings in a file. Useful for reconstructing broken files or reverse engineering data structures in protocols or embedded into binaries
View json_finder.py
#!/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
View cron_helper.sh
#!/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
Algunas resoluciones para los trabajos prácticos propuestos por la cátedra de la materia "Señales y Sistemas"
View common.py
#!/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
@fakuivan
fakuivan / create_sidepanel_folder.bat
Created Mar 7, 2020
Creates a side panel entry for windows explorer
View create_sidepanel_folder.bat
@echo off
:: GUIDs were randomly generated using the command ``python3 -c "import uuid; print(str(uuid.uuid4()).upper())"``
set guid=C3AA96DB-679A-4D75-B53F-F9EBDFEBE6C3
set name=Seafile
set folder=%%userprofile%%\Seafile
set icon=%%programfiles(x86)%%\Seafile\bin\seafile-applet.exe,-2
:: set guid=92EB2F95-3564-4430-8022-4CAF93AB8D96
:: set name=Sync
:: set folder=%%userprofile%%\Sync
You can’t perform that action at this time.