Skip to content

Instantly share code, notes, and snippets.

@s1moe2
s1moe2 / MySQL_CHECK_constraint_simulation.sql
Last active December 19, 2018 14:27
MySQL doesn't support CHECK constraints anymore (https://dev.mysql.com/doc/refman/5.7/en/create-table.html). This is a way to replicate similar behaviour as those constraints but through triggers.
-- create procedure with the logic to avoid repetition
DELIMITER $$
CREATE PROCEDURE check_not_null_fks(
IN old_ley1 INT(10) UNSIGNED,
IN old_key2 INT(10) UNSIGNED,
IN new_key1 INT(10) UNSIGNED,
IN new_key2 INT(10) UNSIGNED
)
BEGIN
@s1moe2
s1moe2 / conf
Created May 9, 2019 11:59
NGINX simple maintenance mode
set $maintenance on;
if ($uri ~* \.(ico|css|js|gif|jpe?g|png|html)(\?[0-9]+)? ) {
set $maintenance off;
}
if ($maintenance = on) {
return 503;
}
@s1moe2
s1moe2 / docker-mysql.md
Last active August 22, 2019 08:29
Local Docker MySQL (5.7) server setup

Local Docker MySQL server setup

  • Pull latest MySQL docker image

docker pull mysql:5.7

  • Create a directory to mount volumes and persist container data

mkdir -p $HOME/docker/volumes/mysql5.7

  • Start the thing

docker run --rm --name mysql5.7-docker -e MYSQL_ROOT_PASSWORD=mypassword -d -p 127.0.0.1:3306:3306 -v $HOME/docker/volumes/mysql5.7:/var/lib/mysql mysql:5.7

@s1moe2
s1moe2 / docker-postgres.md
Last active August 22, 2019 08:41
Local Docker PostgreSQL server setup

Local Docker PostgreSQL server setup

  • Pull latest postgres docker image

docker pull postgres

  • Create a directory to mount volumes and persist container data

mkdir -p $HOME/docker/volumes/postgres

  • Start the thing

docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 127.0.0.1:5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres

@s1moe2
s1moe2 / golearnings_http_req_1.go
Last active April 12, 2020 18:19
Golearnings: HTTP Requests
func GetThings() {
res, err := http.Get("https://httpbin.org/get")
if err != nil {
log.Fatalln(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatalln(err)
}
@s1moe2
s1moe2 / docker-compose.yml
Created November 7, 2020 09:05
Keycloak+PostgreSQL docker compose
version: '3'
services:
postgres-kc:
container_name: keycloak-db
image: postgres:12
volumes:
- ./db:/var/lib/postgresql/data
environment:
POSTGRES_DB: keycloak
@s1moe2
s1moe2 / abstract.js
Last active November 9, 2020 09:43
JavaScript (sort of) Abstract Class
class EmailProvider {
#config = {}
constructor(config) {
this.#config = config
if (new.target === EmailProvider) {
throw new Error('Cannot construct EmailProvider instances directly')
}
if (this.send === EmailProvider.prototype.send) {
@s1moe2
s1moe2 / findTag.go
Created February 9, 2021 16:51
Find commit hash tag by "latest" tag on same image
package main
import (
"bytes"
"encoding/json"
"errors"
"flag"
"fmt"
"net/http"
"os"
@s1moe2
s1moe2 / removeFiles.go
Created March 21, 2021 16:57
Remove all files/directories from a directory 'dir'
func RemoveFiles(dir string) error {
d, err := os.Open(dir)
if err != nil {
return err
}
defer d.Close()
names, err := d.Readdirnames(-1)
if err != nil {
return err
@s1moe2
s1moe2 / replace.go
Created March 21, 2021 16:57
Replace placeholders in text file with Go
func ReplaceInTemplate(filepath string, origString string, replaceString string) error {
input, err := ioutil.ReadFile(filepath)
if err != nil {
return err
}
output := bytes.Replace(input, []byte(origString), []byte(replaceString), -1)
if err = ioutil.WriteFile(filepath, output, 0666); err != nil {
return err