Skip to content

Instantly share code, notes, and snippets.

View siteslave's full-sized avatar

Satit Rianpit siteslave

View GitHub Profile

This script performs a backup of a MySQL database with the following features:

  1. Configuration:

    • Reads configuration from a specified file.
    • Supports different roles (master/slave) for database configuration.
    • Configurable backup directory, number of threads, and other settings.
  2. Password Generation:

    • Generates a random password for the zip file containing the backup.
@siteslave
siteslave / backup.sh
Last active November 6, 2024 14:42
Backup/Restore HOSxP database.
#!/bin/bash
# Author: GitHub Copilot (adapted by Satit Rianpit)
# Date: October 2024
# Description: This script performs the dumping of HOSxP database tables.
# Usage: ./backup.sh -f /path/to/config_file
# Parameters:
# - -f: Specifies the configuration file to use.
# Returns: 0 if successful, 1 if an error occurs.
# Notes: This script requires the 'zip', 'openssl' and 'mysqldump' commands to be installed.

File model

// lib/server/file.ts

import excel from 'excel4node'
import { DateTime } from 'luxon'
import path from 'path'
import { v4 as uuidv4 } from 'uuid'

There might be scenarios where you need to convert an base64 string back to a file. This article will show you how.

The high level view As an example, a base64 string representation of a png image looks like:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...

To convert it back to an image, we need to:

Strip off the data:image/png;base64, part

<script>
	import { goto } from '$app/navigation';

	let isError = false;
	let isSuccess = false;
</script>

<svelte:head>
	<title>PDF</title>
@siteslave
siteslave / README.md
Last active November 6, 2023 07:06
Sveltekit API

src/lib/server/db.js

import knex from 'knex';
import { env } from '$env/dynamic/private';

export default knex({
  client: 'mysql2',
  connection: {
 host: env.DB_HOST,
@siteslave
siteslave / docker-compose.yml
Created November 6, 2023 06:44
PostgreSQL + PostgREST
version: '3'
services:
postgrest:
image: postgrest/postgrest
environment:
PGRST_DB_URI: postgres://authenticator:passwrod@db:5432/app_db
PGRST_OPENAPI_SERVER_PROXY_URI: http://127.0.0.1:3000
PGRST_JWT_SECRET: xxxxxxxxxx
PGRST_DB_MAX_ROWS: 500
PGRST_DB_POOL: 50
@siteslave
siteslave / invoice.js
Created October 31, 2023 07:32 — forked from tusharf5/invoice.js
Invoice Template pdfMake
// try here http://pdfmake.org/playground.html
var dd = {
content: [
{
columns: [
{
image:
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABjCAYAAADeg0+zAAAACXBIWXMAABYlAAAWJQFJUiTwAAAQbUlEQVR42u1dh3tUVRbnf9hvv5WuJBAkhZKEJEAoZkICBKWpVAUERClSFQgl9CZIjYAiuAvLoq4FdEURRQQVFUGa9A5SpUsJ4ez9nXn35c3kvZk3aQQ49/t+32TevHLL+d1T7rkvZWrEPkECgcAeZaQTBAIhiEAgBBEIhCACgRBEIBCCCARCEIFACCIQCEEEAiGIQCAQgggEQhCBQAgiEAhBBAIhiEAgBBEIhCACgRBEIBCCCARCEOkIgUAIIhAIQQQCIYhAIAQRCIQgAoEQRCAQgggEQhCBQAgiEAiEIAKBEEQgEIIIBEIQgUAIIhAIQQQPOh6v08TVMSFIATuzuO7t9Cy35xXmOQVtZyjXBTq3IL/heEGeHxmXQlHxHh/g2P1IlDL3khi6s6rXbkzVajaiiFqNqJofIiyfOF93Pj7dDnoEX9/YdtDz6tCE6xCqYOrz8Il6oi3+z7F+Rvi1y7+t+notWG7r4v8M/34LRlzb61z2hXVc8D0sqgFVikigitXqMvA3jul2RcbdP0QpFRqkTr1mlNj4SYpLbmGLeAWcg/MfrZFEFVSnV41pyJ0daJbTv9Vt1JJiGzQPeF7NhKZch2ACFUhAcH2tpDRTyO0EEe1JUPWxayfqGF03lcKiG1DFCK9wgdhuiaJ/r9swgxJUXYD45AzXGqRuw5aW61pQjTrurkP9MB4YFxxLb9WFuvceQv0Gj2J06z2Y0p7qzP2Cc6rVbBgS+R9agkTFp1Dlx5NowdvL6Pr1v+jSpct09dp1W1y5cpX+vHiJtmzbQVN
<svelte:head>
	<title>หน้าหลัก</title>
</svelte:head>

<header class="flex flex-wrap md:justify-start md:flex-nowrap z-50 w-full text-sm">
	<nav
		class="mt-6 relative max-w-7xl w-full bg-white border border-gray-200 rounded-[36px] mx-2 py-3 px-4 md:flex md:items-center md:justify-between md:py-0 md:px-6 lg:px-8 xl:mx-auto dark:bg-gray-800 dark:border-gray-700"
		aria-label="Global"
	>
@siteslave
siteslave / git-reset-commit.md
Last active August 8, 2023 07:18
ลบ commit history ทั้งหมดทิ้ง เพื่อเริ่มใหม่

Checkout

git checkout --orphan latest_branch

Add all the files

git add -A