Skip to content

Instantly share code, notes, and snippets.

View sroccaserra's full-sized avatar
🐿️

Sébastien Roccaserra sroccaserra

🐿️
View GitHub Profile
@sroccaserra
sroccaserra / thales.lua
Created June 9, 2019 12:35
Illustration du théorème de Thalès avec PICO-8
a = {
x = 64,
y = 44
}
b = {
x = 34,
y = 64
}
GAMEPAD 1
GLOBAL K
GLOBAL Z
Z = 1
INC=0.1
N=2
GLOBAL H
H=87
-- PICO-8 code
local lookup = '0123456789abcdef'
local values = ''
for i =1,16 do
for j = 1,16 do
local num = 1+((i+j-2)%0x10)
values = values .. sub(lookup,num,num)
end
@sroccaserra
sroccaserra / rotating_bobs.lua
Last active May 1, 2019 12:14
Kind of rotating bob effect in PICO-8
-- PICO-8 code
function draw_rotating_bobs()
for i=0,15 do
local x=63+40*cos(t()/4+i/16)
local y=63+40*cos(t()/8+i/16)
spr(1,x,y)
end
end
@sroccaserra
sroccaserra / exploring_sort.md
Last active March 12, 2019 09:34
Exploration de sort

Fichier coco en entrée :

123 2
234 2
123 1
456 1
234 1

Pour trier sur la première colonne sans changer l'ordre par rapport au reste de la ligne :

@sroccaserra
sroccaserra / exploring_awk.md
Last active May 9, 2019 21:05
Utilisation de awk pour faire une visualisation

Voir aussi : http://www.grymoire.com/Unix/Awk.html

awk '{ if($2=="POST") { dot="."} else { dot="X" } if ($1 != ass) { print ass, dots; ass=$1; dots=""; } else { dots=dots""dot; } } END { print ass, dots }'

Pour agréger des lignes comme ça

451776 PATCH
451776 PATCH
456559 PATCH

456559 PATCH

@sroccaserra
sroccaserra / exploring_xargs.md
Last active March 11, 2019 15:00
Exploration de xargs
xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr] [-L number] [-n number [-x]] [-P maxprocs] [-s size] [utility [argument ...]]

La commande xargs ne va pas s'exécuter ligne par ligne, mais elle va regrouper les lignes qu'elle reçoit pour les passer à la commande.

$ find /bin -xdev -print0 | xargs -0 -t -n 10 -P4 true 2>&1 | less
true /bin /bin/cat /bin/echo /bin/launchctl /bin/df /bin/pwd /bin/test /bin/csh /bin/wait4path /bin/unlink
true /bin/sleep /bin/stty /bin/date /bin/ed /bin/expr /bin/pax /bin/bash /bin/kill /bin/sh /bin/ps
true /bin/link /bin/tcsh /bin/dd /bin/mkdir /bin/ksh /bin/hostname /bin/rmdir /bin/mv /bin/ln /bin/ls
true /bin/cp /bin/sync /bin/zsh /bin/chmod /bin/rm /bin/[
@sroccaserra
sroccaserra / bytes_to_image.md
Last active March 13, 2019 22:18
Afficher des octets sous forme d'image

Voir si le fichier commence par une signature connue :

Sinon, pour avoir les images, j'ai jeté un oeil avec xxd, trouvé des données après 2000 octets, et vu un pattern un octet sur deux. Pour info, mon couteau suisse pour l'analyse rapide à la grosse louche des octets impairs :

$ xxd -s 2000 -b 2019\ 01\ 10\ 15H\ 56M.raw   | cut -d ' ' -f 2,4,6 | tr ' ' '\n' | sort | uniq -c

Si on regarde les données à partir de l'octet 0x7d0, on voit un entre-laçage d'octets dans les deux fichiers. Les octets impairs ne prennent que 10 valeurs possibles comprises entre 0x09 (0b00001001) et 0x12 (0b00010010).

@sroccaserra
sroccaserra / wait_for_network_service.md
Created February 11, 2019 14:38
How to wait for a network service to have started

Wait for an http service with wget:

wget --retry-connrefused -T 60 -O- http://localhost:4200

Wait for a port to listen, http or other with netcat:

for i in `seq 60`
do
    nc -z localhost 5432 && echo Success && exit 0

echo -n .

@sroccaserra
sroccaserra / Analyser_un_repo_de_code.md
Last active February 1, 2022 10:51
Analyser rapidement un répo de code

Git + Bash

Les âges des branches

$ git for-each-ref --sort=authordate --format '%(authordate:relative) %(refname:short)' refs/heads

Les 100 fichiers qui changent le plus souvent