Skip to content

Instantly share code, notes, and snippets.

View khasky's full-sized avatar
💭
Failing to plan is planning to fail

Ryan Khasky khasky

💭
Failing to plan is planning to fail
View GitHub Profile
@khasky
khasky / rgbaToRgb.ts
Created June 2, 2021 17:01
TypeScript RGBA to RGB
interface RGBAtoRGBOptions {
toColorRGBA: string;
backgroundColorRGB?: string;
}
function rgbaToRgb({ toColorRGBA, backgroundColorRGB = 'rgb(255,255,255)' }: RGBAtoRGBOptions) {
const [r, g, b, a] = toColorRGBA
.replace(/rgba|\(|\)/g, '')
.split(',')
.map((str) => parseInt(str, 2));
@khasky
khasky / mysql-backup.sh
Last active February 21, 2021 19:26
Bash MySQL backup for all databases
#!/bin/bash
USER=root
PASSWORD=root
DATE_NOW="`date '+%Y-%m-%d_%H-%M-%S'`"
DIR=/var/local/backup
DATABASES=`mysql -u$USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
echo "Databases found: $DATABASES"
@khasky
khasky / khasky.com-reverse-proxy.conf
Created July 22, 2020 11:57
Apache2 reverse proxy for NodeJS server
<IfModule mod_ssl.c>
<VirtualHost *:443>
# ...config
# NodeJS server start
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
@khasky
khasky / khasky.com-le-ssl.conf
Created July 22, 2020 11:53
Apache2 VPS https conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin hello@khasky.com
ServerName khasky.com
ServerAlias www.khasky.com
DocumentRoot /var/www/khasky.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/khasky.com/fullchain.pem
@khasky
khasky / khasky.com.conf
Created July 22, 2020 11:50
Apache2 VPS http conf
<VirtualHost *:80>
ServerAdmin hello@khasky.com
ServerName khasky.com
ServerAlias www.khasky.com
DocumentRoot /var/www/khasky.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =khasky.com [OR]
@khasky
khasky / mysql-backup-tar-gz.sh
Last active February 21, 2021 19:25
Bash MySQL backup to tar.gz for single database
#!/bin/bash
MYSQL_USER=root
MYSQL_PASS=root
MYSQL_DB=test
BACKUP_DIR=/var/local/backup
LOGS_DIR=/var/log
# Equals to 3 last days