Skip to content

Instantly share code, notes, and snippets.

@s1moe2
s1moe2 / 20181118235404-some-migration.js
Last active February 4, 2022 17:34
Sequelize migration add/drop multiple columns (transacting)
// NOTE: MySQL does not support transactional DDL (https://dev.mysql.com/doc/internals/en/transactions-notes-on-ddl-and-normal-transaction.html)
// You should use this with a (cool) DBMS such as PostgreSQL.
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.addColumn('table_name', 'column_name1', {
type: Sequelize.STRING
}, { transaction: t }),
@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-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 / 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 / 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 / clone.go
Last active February 14, 2024 06:01
Clone private GitHub repo with go-git
// SSHClone clones a private GitHub repository using SSH, in the directory passed as parameter
func SSHClone(dest string) error {
var publicKey *ssh.PublicKeys
sshKey, err := ioutil.ReadFile("/Users/youruser/.ssh/id_rsa")
if err != nil {
return err
}
publicKey, err = ssh.NewPublicKeys("git", sshKey, "")
if err != nil {
@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"