Skip to content

Instantly share code, notes, and snippets.

View garraflavatra's full-sized avatar

Romein van Buren garraflavatra

View GitHub Profile
@garraflavatra
garraflavatra / nginx-php-mariadb-installer-debian12.bash
Last active August 13, 2023 18:00
Install nginx, PHP, FPM, MariaDB & Certbot on Debian 12
View nginx-php-mariadb-installer-debian12.bash
# 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.
View git-fork-update.bash
#!/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
View gitlines.sh
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 July 13, 2022 20:14
Meta tags component for SvelteKit
View meta.svelte
<script lang="ts">
import { page } from '$app/stores';
export let title: string;
export let description: string;
export let image = '/img/social/preview.jpg';
export let path = $page.url.pathname;
export let domain = 'https://www.mysite.com';
export let titleSuffix = 'My site';
@garraflavatra
garraflavatra / get-user-id.cs
Created September 26, 2021 11:26
ASP.NET Core: get current user's ID
View get-user-id.cs
using Microsoft.AspNetCore.Identity;
string UserID = User.FindFirstValue(ClaimTypes.NameIdentifier);
View button-animation-zoom.scss
.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
View jpeg-tp-jpg.sh
find . -type f -name '*.jpeg' -print0 | xargs -0 rename 's/\.jpeg/\.jpg/'
@garraflavatra
garraflavatra / dates.py
Created July 10, 2021 15:00
Get a formatted date in Python. See https://www.w3schools.com/python/gloss_python_date_format_codes.asp for an overview of all formatting codes.
View dates.py
import datetime
x = datetime.datetime.now()
print(x.strftime("%Y-%m-%d %H:%M:%S"))
@garraflavatra
garraflavatra / wp-term-metadata.php
Created July 9, 2021 15:18
Get metadata array of the current term in WordPress.
View wp-term-metadata.php
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
@garraflavatra
garraflavatra / wp-query-custom-taxonomy.php
Last active July 9, 2021 15:07
How to query WordPress posts with a custom taxonomy term.
View wp-query-custom-taxonomy.php
<?php
$posts = get_posts(
array(
'numberposts' => 20,
'post_type' => 'custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'custom_taxonomy',
'field' => 'slug',
'terms' => array( 'termslug1', 'termslug2' )