Skip to content

Instantly share code, notes, and snippets.

@m-ocean-it
m-ocean-it / get-user-home-dir.sh
Created August 31, 2022 13:01
Get some user's home directory
#!/bin/zsh
cat /etc/passwd | grep username | cut -d : -f 6
@m-ocean-it
m-ocean-it / backup.sh
Last active August 31, 2022 13:22
Backup PostgreSQL DB running in Docker container
#!/bin/zsh
# Constants {
postgres_container_name=""
main_user=""
# }
# Make a copy of the DB files within the container
postgres_home_dir=$(docker exec --user postgres $postgres_container_name bash -c "echo \$HOME")
@m-ocean-it
m-ocean-it / index.html
Last active July 28, 2022 06:31
Editable HTML table with AJAX updates
// Source: https://codewithmark.com/easily-edit-html-table-rows-or-cells-with-jquery
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function($)
@m-ocean-it
m-ocean-it / script.js
Created April 18, 2022 12:36
AppScript (Google Sheets): MIN & MAX functions for ARRAYFORMULA
function ARRAYMIN(xx, yy) {
return xx.map((x, idx) => {
const y = yy[idx]
return Math.min(x, y)
}
}
function ARRAYMAX(xx, yy) {
return xx.map((x, idx) => {
const y = yy[idx]
@m-ocean-it
m-ocean-it / try_until_success.py
Last active February 28, 2022 16:04
Function for running some task until no exception arises
from time import sleep
def try_until_success(task,
delay=0,
number_of_tries=3,
exception_to_catch=Exception):
success = False
tries = 0
@m-ocean-it
m-ocean-it / shamir_split_to_files.py
Last active February 26, 2022 23:57
Split a secret using Shamir Secret Sharing Scheme and then put each share in its own file with a specified note
#!/bin/python3
'''
Split a secret using Shamir Secret Sharing Scheme and then put each
share in its own file with a specified note.
Uses: ssss v0.5
'''
import subprocess
@m-ocean-it
m-ocean-it / batch_gpg.py
Last active February 26, 2022 23:27
Encrypt several files individually with GPG
#!/bin/python3
'''
Encrypt several files individually with GPG.
NOTE: The script moves all original files to ./trash
Dependencies:
- gpg (GnuPG) 2.2.19
- libgcrypt 1.8.5
@m-ocean-it
m-ocean-it / flaskapp.py
Last active May 18, 2021 07:46
Upload files to a web server using Flask
import os
from flask import Flask, flash, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = 'path/to/upload/folder'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER