Skip to content

Instantly share code, notes, and snippets.

@aryelgois
aryelgois / nmaplocal.sh
Created May 3, 2024 22:05
nmap local: LAN / WLAN
#!/bin/sh
set -eu
inet=$(ip -br -4 address | grep ' UP ' | awk 'NR==1{print $3}')
if [ -n "$inet" ]
then echo "Scanning $inet"
else >&2 echo "inet not found"; exit 1
fi
nmap "$@" "$inet" | GREP_COLORS='ms=1;97' grep --color=always -e ^ -e '^Nmap scan.*'
@aryelgois
aryelgois / benchmark_strlen.c
Last active February 20, 2024 19:23
Benchmark strlen vs check \0 vs snprintf
#include <stdio.h>
#include <string.h>
#include <time.h>
// header ---------------------------------------------------------------- {{{1
typedef struct {
clock_t start;
clock_t end;
} Elapsed;
@aryelgois
aryelgois / make_cert.sh
Created January 11, 2024 17:36
Self Signed CA and Certificate
#!/usr/bin/env bash
set -eu
### SETTINGS ###
certs_dir=~/certs
country=BR
state=
#!/bin/sh
git add -A
git commit --no-verify -m 'stuff'
git push -f
type UnaryFn<T, R> = (param: T) => R
export function maybeCall<T, R>(fn: UnaryFn<T, R>): UnaryFn<T | null, R | null>;
export function maybeCall<T, R>(fn: UnaryFn<T, R>, value: T | null): R | null;
export function maybeCall<T, R>(fn: UnaryFn<T, R>, value?: T | null) {
if (value === undefined) {
return (v: T | null) => maybeCall(fn, v)
}
return value !== null ? fn(value) : null
}
@aryelgois
aryelgois / puzzle_four_horses.ts
Last active May 27, 2022 22:25
Solves Professor Layton puzzle "Four Horses"
/**
* You have four horses, all of which travel at different speeds.
* In travelling from point A to point B, these horses take one, two,
* four and six hours respectively.
*
* One day, you decide to move all your horses from point A to point B.
* Howerver, you can only move a maximum of two horses at a time, and
* you need to ride a horse back to point A each time you return to move
* your other horses. Knowing you can only move as fast as the slowest
* horse you're travelling with, what's the fewest number of hours it
@aryelgois
aryelgois / combinations.ts
Created May 27, 2022 21:46
Get combinations of array elements
export function* getCombinations<T>(arr: T[], size: number): Generator<T[]> {
if (size < 1) {
throw new Error('Combination size must be at least 1')
}
if (arr.length === 0) {
yield []
} else if (size === 1) {
for (const el of arr) {
yield [el]
@aryelgois
aryelgois / permute.ts
Last active May 27, 2022 21:45
Permute elements in array
export function* permute<T>(arr: T[], m: T[] = []): Generator<T[]> {
if (arr.length === 0) {
yield m
} else {
for (let i = 0; i < arr.length; i++) {
const curr = arr.slice()
const next = curr.splice(i, 1)
yield* permute(curr.slice(), m.concat(next))
}
}
@aryelgois
aryelgois / glb2usdz
Created May 12, 2021 01:29
Convert .glb to .usdz with docker
#!/bin/sh
set -eu
cd "$(dirname "$1")"
input=$(basename "$1")
output=${input%.glb}.usdz
exec docker run -it --rm \
💩:
@echo HOLY SHIT!