Skip to content

Instantly share code, notes, and snippets.

View utarn's full-sized avatar

Utharn Buranasaksee utarn

View GitHub Profile
services.AddAuthentication()
.AddOpenIdConnect("Line", "Line", options =>
{
options.CallbackPath = "/signin-line";
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.RequireHttpsMetadata = true;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
@utarn
utarn / ApplicationDbContextInitialiser.cs
Last active March 9, 2024 11:32
TimeScaleDb Initializer
using System.Reflection;
using VaultApi.Domain.Constants;
using VaultApi.Domain.Entities;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Npgsql;
using VaultApi.Domain.Common;
@utarn
utarn / nextcloud.conf
Created February 19, 2024 09:11
Nextcloud nginx configuration
server {
server_name nextcloud.mydomain.com;
client_max_body_size 2G;
location / {
proxy_pass http://localhost:5001;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_cache_bypass $http_upgrade;
@utarn
utarn / docker-compose.yml
Last active February 20, 2024 02:44
Nextcloud docker-compose.yml
version: '3'
services:
db:
image: mariadb:10.6
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- ./database:/var/lib/mysql
environment:
@utarn
utarn / tbw.sh
Created October 7, 2023 07:06
Check total byte written
#!/bin/bash
declare -A custom_names
custom_names["8427e3af:14f642d8:316fd036:e279d458"]="/root"
custom_names["f2e76944:da560738:512c4030:54026dcf"]="/opt"
for drive in /dev/sd[a-e]; do
if smartctl -A "$drive" | grep -q 'Host_Writes_GiB'; then
md_name=$(mdadm --examine "$drive" | grep "Array UUID" | awk '{print $4}')
if [ -n "$md_name" ]; then
@utarn
utarn / autoUpdate.sh
Last active September 12, 2023 22:54
Auto update docker compose if new image is found for all subdirectories on given base path
## Add to crontab
# */5 * * * * /root/autoUpdate.sh | ts | tee -a /var/log/updater/updater-$(date +'\%Y-\%m-\%d').log
#!/bin/bash
# Define a function for null coalescing
coalesce() {
if [ -n "$1" ]; then
echo "$1"
else
echo "$2"
@utarn
utarn / install.sh
Last active August 16, 2023 02:50
Systemd Wireguard auto re-resolve DNS for dynamic DNS wireguard server
#!/bin/bash
# This script installs a systemd timer template named WireguardReResolveDNS.(service|timer)
# to run every 30 seconds. Requires that wireguard-tools is installed.
# Enable using e.g. systemctl enable --now wg-reresolve-dns@wg0.timer
# You need to do that separately for each wireguard interface
export NAME=wg-reresolve-dns@
cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
@utarn
utarn / oh-my-posh.json
Created July 16, 2022 00:03
oh my posh on macos/windows
# install oh-my-posh using brew
# eval "$(oh-my-posh init zsh --config ~/shell.json)"
# eval "$(oh-my-posh completion zsh)"
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"final_space": true,
"blocks": [
{
"type": "prompt",
@utarn
utarn / addIp.sh
Created May 24, 2022 02:08
Add docker container IP to hosts file.
#!/bin/sh
#
# Retrieve the argument and create a name for a tmp file
#
processfile=$1
tmpfile=${1}.tmp
#
# for all running docker containers
@utarn
utarn / Program.cs
Created January 22, 2022 15:04
Dependency Injection for console app
namespace AppClient
{
static class Program
{
private static IConfiguration _configuration;
static async Task Main()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);