Skip to content

Instantly share code, notes, and snippets.

View garraflavatra's full-sized avatar

Romein van Buren garraflavatra

View GitHub Profile
@garraflavatra
garraflavatra / django-compose-rollout.sh
Created March 31, 2024 16:20
Zero-downtime deployment script for Docker Compose, Django, and Nginx.
#!/bin/sh
#
# Zero-downtime deployment script for Docker Compose and Nginx (+ Django)
# Inspired by https://www.tines.com/blog/simple-zero-downtime-deploys-with-nginx-and-docker-compose
#
# (c) Romein van Buren 2024
# SPDX-License-Identifier: WTFPL
#
reload_nginx() {
@garraflavatra
garraflavatra / nginx.gzip.conf
Created December 2, 2023 14:42
Nginx gzip configuration
http {
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/java>
}
@garraflavatra
garraflavatra / find-777.sh
Last active December 9, 2023 20:36
Find all 777 directories on Linux systems
# Find all 777 files:
sudo find / -type d -perm 777
# Find all world-writable files:
sudo find / -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print
# Find all files without owner:
sudo find / -xdev \( -nouser -o -nogroup \) -print
@garraflavatra
garraflavatra / nginx-php-mariadb-installer-debian12.bash
Last active August 13, 2023 18:00
Install nginx, PHP, FPM, MariaDB & Certbot on Debian 12
# Update apt repositories
sudo apt update -y
sudo apt upgrade -y
# Install nginx & PHP
sudo apt install -y nginx php8.2
sudo apt-get install -y php8.2-{fpm,cgi,mysql,curl,xsl,gd,common,xml,zip,xsl,soap,bcmath,mbstring,gettext,imagick,sqlite3,intl}
sudo nano /etc/nginx/sites-available/default
# Add the following / update the file to contain it:
@garraflavatra
garraflavatra / git-fork-update.bash
Last active June 17, 2023 10:38
Bash script that keeps all Git repositories within a specified directory up to date.
#!/usr/bin/bash
#
# This script keeps all Git repositories within a specified directory up to date.
#
# Consider the following example. The linux and curl repositories will be updated
# when you run this in the gitforks directory.
#
# gitforks/
# linux/.git/ linux Git repository
@garraflavatra
garraflavatra / gitlines.sh
Created December 29, 2021 10:19
Git: how many lines did a user change? Modified https://gist.github.com/Xeoncross/4020489#gistcomment-3989215
git log --shortstat --author "Romein van Buren" \
| egrep "file[s] changed" \
| sed 's/changed, \([0-9]\+ deletions\)/changed, 0 insertions(+), \1/g' \
| awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed:", files, "- lines inserted:", inserted, "- lines deleted:", deleted}'
@garraflavatra
garraflavatra / meta.svelte
Last active October 23, 2023 10:22
Meta tags component for SvelteKit
<script>
import { page } from '$app/stores';
export let type = 'website'; // or article, or music.album etc. See https://ogp.me/#types
export let title = '';
export let description = '';
export let image = '/img/social/preview.jpg';
export let path = $page.url.pathname;
@garraflavatra
garraflavatra / get-user-id.cs
Created September 26, 2021 11:26
ASP.NET Core: get current user's ID
using Microsoft.AspNetCore.Identity;
string UserID = User.FindFirstValue(ClaimTypes.NameIdentifier);
.button {
// border: 2px solid currentColor;
// border-radius: 3rem;
// color: #ff0;
// font-family: roboto;
// font-size: 4rem;
// font-weight: 100;
overflow: hidden;
// padding: 1rem 2rem;
position: relative;
@garraflavatra
garraflavatra / jpeg-tp-jpg.sh
Last active July 18, 2021 07:15
Rename all *.jpg to *.jpeg or vice-versa. Thanks to https://superuser.com/a/1023909
find . -type f -name '*.jpeg' -print0 | xargs -0 rename 's/\.jpeg/\.jpg/'