Skip to content

Instantly share code, notes, and snippets.

View simonesestito's full-sized avatar
🇮🇹

Simone Sestito simonesestito

🇮🇹
View GitHub Profile
@simonesestito
simonesestito / client.mo
Last active January 11, 2023 16:10
FIFO Modelica explanation: more available at https://www.overleaf.com/read/xtjqpcnzshmj
block Client
parameter Real T = 1; // O meno!
// Variabili lato lettura (server -> client)
OutputBoolean readsignal;
InputInteger readfifodata[1];
InputBoolean datavailable;
// Variabili lato scrittura (client -> server)
OutputInteger writefifodata[2]; // M = 2
@simonesestito
simonesestito / main.go
Last active January 7, 2023 09:51
CFG derivation tester
package main
import (
"fmt"
"strings"
)
func main() {
// ! Edit grammar
cfg := NewGrammar('S', map[byte]Rule{
@simonesestito
simonesestito / update-cloudflare-nginx.sh
Created October 10, 2022 13:57
Nginx whitelist update script (403 for not whitelisted)
#!/bin/bash
set -e
#
# Whitelist config file.
#
# Make sure
# include /etc/nginx/conf.d/*.conf;
# is present inside the http {} block of
@simonesestito
simonesestito / backup.sh
Created September 29, 2022 19:23
Backup WordPress Docker instance
#!/bin/bash
#
# RESTORE COMMANDS
#
# Database:
# cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
#
# Files:
# JOIN parts with cat filename.tar.gz.* > filename.tar.gz
@simonesestito
simonesestito / fix_chmod.py
Last active October 28, 2022 06:55
Chmod all dirs to 755 and all files to 644, apart from .sh files
#!/bin/env python3
'''
Super simple script to set chmod 644 to every file and 755 to every directory.
Useful, for instance, when moving files (in WSL) from the Windows Host to the Linux machine.
As we know, files in /mnt/c/ have the eXecute permission flagged, which is not desiderable.
'''
import os, sys
@simonesestito
simonesestito / calc_paths.py
Last active May 12, 2022 09:34
Finding the count of paths with K turns from corner to corner in a square box
'''
Based on https://math.stackexchange.com/a/1080170
'''
from functools import lru_cache, reduce
import operator
@lru_cache()
def fact(n):
assert n >= 0
@simonesestito
simonesestito / whatsapp_timestamp.sh
Created March 27, 2022 17:10
WhatsApp timestamp fix
#!/bin/bash
cd /sdcard/Android/media/com.whatsapp/WhatsApp/Media
while read path; do f=$(basename "$path"); touch -d "${f:4:4}-${f:8:2}-${f:10:2}T12:00:00z" "${path}"; done < <(find . -regextype posix-extended -regex ".*/[[:alpha:]]{3}-[[:digit:]]{8}-.*")
@simonesestito
simonesestito / README.md
Last active February 28, 2024 15:54
Server setup script

Server initial setup script

Configuration

This script was made for personal purposes, but it can still be useful to many. You NEED to change variables inside the script, like the SSH public key.

Usage

On a new Ubuntu server, run the following command:

@simonesestito
simonesestito / README.md
Created October 14, 2021 06:31
Calculate MCD and Bezout's identity

Calculate MCD and Bezout's identity

Run the script using Python

python mcd.py <first_number> <second_number>

Or just run the script and the numbers will be requested in interactive mode.

@simonesestito
simonesestito / README.md
Last active November 4, 2020 15:25
Calcolo combinatorio: tabella verità, SOP e POS

Tabella della verità, forma SOP canonica e POS canonica

Come si usa

  • Scaricare i file lib.py e src.py
  • Nel file src.py, scrivere l'espressione nella lambda.

Per scrivere l'espressione, usare i simboli:

  • NOT: ~ (non !)
  • OR: | (non || o +)