Skip to content

Instantly share code, notes, and snippets.

View gist:de1b3c9c332a20d5c9ec3d1715c13e37
CREATE TABLE data (id int PRIMARY KEY);
INSERT INTO data SELECT * FROM generate_series(1,5000000);
----
EXPLAIN ANALYZE
WITH r AS (
SELECT (random() * (SELECT count(*) FROM data))::int x
)
SELECT data.*
FROM r
View gist:5a36cfce7219384bd16a79aee7cec6bb
pgo create cluster postgres -n pgo --database=keycloak --username=admin --password=admin
# wait for startup
cat <<-EOF > kc-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: keycloak
labels:
View password.js
const PASSWORD_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ 'abcdefghijklmnopqrstuvwxyz'
+ '01234567890'
+ '!#$%&()*+,-./:;<=>?@[]^_`{|}~\/"\' ';
function generateRandomPassword(passwordLength=16) {
// if crypto not defined, bail
if (!window.crypto) {
throw new Error('The "crypto" library is not available');
}
View quickstart-postgresql-cert.sh
#!/bin/bash
# SET THIS TO BE YOUR DESIRED USERNAME
export MY_USER_NAME_FOR_CERT=`whoami`
# This directory is optional, but will use it to keep the CA root key safe
mkdir keys certs
chmod og-rwx keys certs
# Set up a directory that will serve as the pgconf mount
@jkatz
jkatz / encrypt_password.py
Last active Jan 5, 2022
Methods to create password verifiers for PostgreSQL
View encrypt_password.py
"""
Generate the password hashes / verifiers for use in PostgreSQL
How to use this:
pw = EncryptPassword(
user="username",
password="securepassword",
algorithm="scram-sha-256",
)
@jkatz
jkatz / scram_poc.py
Last active Oct 15, 2019
SCRAM-SHA-256 POC for PostgreSQL; client does not support channel binding; Py3+
View scram_poc.py
import base64
import hashlib
import hmac
import re
import secrets
import socket
class SCRAMAuthentication(object):
AUTHENTICATION_METHOD = b"SCRAM-SHA-256"
DIGEST = hashlib.sha256
@jkatz
jkatz / setup.sh
Last active Aug 18, 2018
Example with PostgreSQL + PostGIS
View setup.sh
#!/bin/bash
mkdir postgres
cd postgres
docker volume create --driver local --name=pgvolume
docker volume create --driver local --name=pga4volume
docker network create --driver bridge pgnetwork
@jkatz
jkatz / setup.sh
Last active Mar 3, 2021
Install PostgreSQL 10 & pgAdmin 4 with Docker
View setup.sh
#!/bin/bash
mkdir postgres
cd postgres
docker volume create --driver local --name=pgvolume
docker volume create --driver local --name=pga4volume
docker network create --driver bridge pgnetwork
View gist:ca333b411831833ef2d089097448f6da
diff --git a/media/img/docs/books/plpgsql_y_otros_lenguajes.jpg b/media/img/docs/books/plpgsql_y_otros_lenguajes.jpg
new file mode 100644
index 0000000..8c1e1ee
Binary files /dev/null and b/media/img/docs/books/plpgsql_y_otros_lenguajes.jpg differ
diff --git a/templates/pages/docs/books.html b/templates/pages/docs/books.html
index f798f8e..3bb4a49 100644
--- a/templates/pages/docs/books.html
+++ b/templates/pages/docs/books.html
@@ -12,6 +12,22 @@
View models.py
from django.conf import settings
from django.core.mail import send_mail
from django.db import models, transaction
from django.db.models.signals import post_save
from .tasks import *
class Contact(models.Model):
"""store contact information for emailing a user in the address book"""
user = models.ForeignKey(settings.AUTH_USER_MODEL, help_text="A reference to the User for the purpose of his/her address book")