Skip to content

Instantly share code, notes, and snippets.

@jhrr
jhrr / mysql-to-postgres.sh
Created February 6, 2024 14:19 — forked from dougvj/mysql-to-postgres.sh
Mysql to Postgres SQL file conversion
# Adapted from github comment:
# https://github.com/dimitri/pgloader/issues/782#issuecomment-1136067634
if [ -z "$3" ]; then
echo "Usage: $0 <db name> <mysql dump> <psql dump output>"
echo "Requirements: docker"
exit 1
fi
if ! command -v docker &> /dev/null
@jhrr
jhrr / _HowToSetupAWSWAFv2.md
Created July 3, 2023 22:13 — forked from masayoshi644/_HowToSetupAWSWAFv2.md
How to setup AWS WAFv2
@jhrr
jhrr / Export MUBI lists.js
Created February 12, 2021 18:26
Export MUBI lists
$('#multi-films .film-grid').children().map(function() {
var $this = $(this),
rank = $this.find('.list-film-position').text().trim(),
title = $this.find('.film-title').text().trim(),
dirYear = $this.find('.director-year').text().trim(),
re = dirYear.match(/^(.+), (\d+)$/),
dir = re ? re[1] : dirYear,
year = re ? re[2] : '';
return [rank, title, year, dir].join('\t');
}).get().join('\n');
@jhrr
jhrr / create_function_plv8_cuid.sql
Created October 27, 2020 14:49 — forked from notakaos/create_function_plv8_cuid.sql
cuid for PostgreSQL with PL/v8
-- original code: https://github.com/ericelliott/cuid
-- Add the "plv8" extension
create extension if not exists "plv8";
-- Add the "pgcrypto" extension
create extension if not exists "pgcrypto";
\dx
-- Connect a database
#!/usr/bin/env sh
# checks to see if running
launchctl list | grep elasticsearch
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
launchctl remove homebrew.mxcl.elasticsearch
pkill -f elasticsearch
@jhrr
jhrr / restore.sh
Created March 18, 2019 16:58 — forked from jgillman/restore.sh
pg_restore a local db dump into Docker
# Assumes the database container is named 'db'
DOCKER_DB_NAME="$(docker-compose ps -q db)"
DB_HOSTNAME=db
DB_USER=postgres
LOCAL_DUMP_PATH="path/to/local.dump"
docker-compose up -d db
docker exec -i "${DOCKER_DB_NAME}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_HOSTNAME}" < "${LOCAL_DUMP_PATH}"
docker-compose stop db
@jhrr
jhrr / access_from_web.md
Created August 8, 2018 11:14 — forked from jasperf/access_from_web.md
MySQL Commands to create users, database, password and grant necessary privileges from the command line
mysql> CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'localhost' WITH GRANT OPTION;
mysql> CREATE USER 'user_name'@'%' IDENTIFIED BY 'password';

mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'%' WITH GRANT OPTION;

@jhrr
jhrr / gist:21e83ec6eec7afcaf17823baea58b400
Last active March 20, 2018 15:52 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
"""
Logical deletion for Django models. Uses is_void flag
to hide discarded items from queries. Overrides delete
methods to set flag and soft-delete instead of removing
rows from the database.
"""
from django.apps import apps
from django.contrib.admin.utils import NestedObjects
from django.db import models
from django.db.models import signals