Skip to content

Instantly share code, notes, and snippets.

View jrichardsz's full-sized avatar

JRichardsz jrichardsz

View GitHub Profile
@jrichardsz
jrichardsz / parse init file with javascript.js
Created April 21, 2024 21:03
parse init file with javascript
function parseIniString(data) {
var regex = {
section: /^\s*\[\s*([^\]]*)\s*\]\s*$/,
param: /^\s*([^=]+?)\s*=\s*(.*?)\s*$/,
comment: /^\s*;.*$/
};
var value = {};
var lines = data.split(/[\r\n]+/);
var section = null;
lines.forEach(function (line) {
@jrichardsz
jrichardsz / docker Overlay2 size too big
Created April 19, 2024 15:55
docker Overlay2 size too big
du -h . --max-depth=1 | sort -r -h
docker system df
du -shc /var/lib/docker/*
docker ps --size
du -shc /var/lib/docker/overlay2/*/diff
@jrichardsz
jrichardsz / docker truncate logs - snippets.md
Created April 17, 2024 15:26
docker truncate logs - snippets

/acme/truncate_log.sh

echo "clear log : $(date)"
df -h
name=$(docker ps --format '{{.Names}}')
log_file=$(docker inspect --format='{{.LogPath}}' $name)
du -h "${log_file}" | cut -f 1
echo "" > $(docker inspect --format='{{.LogPath}}' $name )
du -h "${log_file}" | cut -f 1
@jrichardsz
jrichardsz / let's encrypt certbot snippets - interactive.md
Last active April 16, 2024 05:07
let's encrypt certbot snippets

install

sudo apt update
sudo apt install snapd
sudo snap install --classic certbot
docker run -it -v certs:/etc/letsencrypt --entrypoint /bin/sh certbot/certbot:latest
@jrichardsz
jrichardsz / cert snippets.md
Last active April 14, 2024 22:15
cert snippets

cert creation with linux

openssl req -new -x509 -keyout cert.pem -out cert.pem -days 365 -nodes -subj '/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com'

openssl req -new -x509 -keyout private.pem -out cert.pem -days 365 -nodes -subj '/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com'

cert to string

@jrichardsz
jrichardsz / args_shell_parser-default.md
Last active April 14, 2024 21:36
bash argument parser, bashargument

foo.sh

#!/bin/bash

for ARGUMENT in "$@"
do
   KEY=$(echo $ARGUMENT | cut -f1 -d=)

 KEY_LENGTH=${#KEY}
@jrichardsz
jrichardsz / c# unit tests.cs
Created April 12, 2024 16:40
c# unit tests
using NUnit.Framework;
using System;
[TestFixture]
public class Tests
{
[Test]
public static void Test1()
{
Assert.AreEqual("emocleW", Kata.SpinWords("Welcome"));
@jrichardsz
jrichardsz / Helper.js
Created April 11, 2024 23:03
html table with javascript, array double to table html
function Helper() {
function getCells(data, type) {
return data.map(cell => `<${type} style="border: 1px solid #000;" >${cell}</${type}>`).join('');
}
function createBody(data) {
return data.map(row => `<tr style="border: 1px solid #000;" >${getCells(row, 'td')}</tr>`).join('');
}
this.generateTable = (data) => {
@jrichardsz
jrichardsz / ffmpeg flip mirror invert.md
Created July 10, 2022 20:26
ffmpeg flip mirror invert
@jrichardsz
jrichardsz / opera snippets
Created April 9, 2024 01:31
opera snippets
https://addons.opera.com/en/extensions/details/vertical-tabs/