Skip to content

Instantly share code, notes, and snippets.

View fakuivan's full-sized avatar

fakuivan

  • Posadas, Misiones, Argentina
  • 23:33 (UTC -03:00)
View GitHub Profile
#!/usr/bin/env bash
# Returns an eval-safe representation of the bash function that when evaluated prints its name,
# useful when redefining functions
function_copy_rnd () {
local rand_prefix="$(head /dev/urandom | tr -dc A-Za-z | head -c 8)_"
local name="$1"
local decl;
decl="$(declare -f "$name")" || return $?
echo "${rand_prefix}${decl}; echo $(printf "%q" "${rand_prefix}${name}")"
@fakuivan
fakuivan / engineer.md
Last active September 29, 2019 20:35
HP Prime CAS "programs" I made to solve multivariable calculus, statistics and physics 2 exercises

engineer.exe

These are scripts I use to serialize some of the practice exercises we get on multivariable calculus, statistics and physics 2 class, they are not meant to be easy to understand or a tutorial on how to write CAS programs on the HP Prime graphing calculator but rather a set of solutions I was able to come up with, for some a valuable resource nonetheless.

Calculus 2

Multivariable Taylor series

@fakuivan
fakuivan / example.py
Last active October 11, 2019 00:51
Simple CSV parser function and example plotter program compatible with _some_ RIGOL oscilloscopes
#!/usr/bin/env python3
from oscilloscope import parse_csv_export, ParsedCSV
import argparse
from io import TextIOWrapper
import matplotlib.pyplot as plt
def main():
parser = argparse.ArgumentParser(description="Example plotter")
parser.add_argument("infile", type=argparse.FileType('r'))
@fakuivan
fakuivan / apply_zt_rules.sh
Created February 11, 2020 06:40
jq based bash script used to configure zerotier's rule engine via the controller API
#!/usr/bin/env bash
run_on_ztncui () {
(source ~/containers/ztncui.sh && ztncui-compose exec -T ztncui bash -c "$1"); return $?
}
NETWORKS="$(run_on_ztncui 'curl -s -X GET --header "X-ZT1-Auth: $ZT_TOKEN" "$ZT_ADDR"/controller/network')"
for rules_file in ./rules/*.ztrules; do
nwid="$(python3 -c "import pathlib, sys; print(pathlib.Path(sys.argv[1]).stem)" "$rules_file")" &&
@fakuivan
fakuivan / maincra_casita_finder.py
Last active February 25, 2020 14:22
Script for determining the block_id/chunk density for a specific minecraft world
#!/usr/bin/env python3
from nbt.nbt import NBTFile
from nbt.chunk import McRegionChunk
from nbt.world import WorldFolder, AnvilWorldFolder, McRegionWorldFolder
from pathlib import Path
from pprint import pprint
from typing import List, Dict, Tuple, Optional, Generator, Iterable, Union, NamedTuple, DefaultDict, Any
from collections import defaultdict
from io import TextIOWrapper
import json
@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
@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 / 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.
@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 / 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]]