commit 51c8b33ca01139dfb7d513fff61837daa383e503 Author: Shane Date: Sun Jul 30 20:49:44 2023 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..662f8ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +postgres/ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..9482bdf --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# Milk Sad Lookup + +Insert many rows of sha256 hashes into a Postgres database. + +1. Install `postgress-client`: + +```shell +sudo apt install postgres-client +``` + +2. Install Docker +3. Install Python dependencies: + +```shell +pip install psycopg2 +``` + +4. Run the database via Docker: + +```shell +./mock/postgres.sh +``` + +5. Configure the database: +- Log into `psql shell`: + +```shell +psql -h localhost -p 5432 -U postgres +``` + +Password: `test` + +- Create Database, table, and index: + +```shell +postgres=# CREATE DATABASE hashes; +postgres=# \c hashes; +hashes=# CREATE TABLE hashes(id BYTEA); +hashes=# CREATE INDEX hashes_id on hashes(id); +``` + +6. Hammer time: + +```shell +./mock/insert_into.py +``` \ No newline at end of file diff --git a/mock/insert_into.py b/mock/insert_into.py new file mode 100755 index 0000000..d6d4ffb --- /dev/null +++ b/mock/insert_into.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +import uuid +import hashlib +import psycopg2 + +conn = psycopg2.connect("user=postgres password=test host=0.0.0.0 dbname=hashes") + +RANGE = 4294967295 + +cur = conn.cursor() +for entry in range(RANGE): + hash = hashlib.sha256(str(uuid.uuid4()).encode()).digest() + cur.execute("""INSERT INTO hashes(id) VALUES(%s);""", (hash, )) + if entry % 100000 == 0: # Print progress every 100,000 commits + conn.commit() + print(entry) + print(hash) +conn.close() diff --git a/mock/postgres.sh b/mock/postgres.sh new file mode 100755 index 0000000..ee1ef77 --- /dev/null +++ b/mock/postgres.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +docker run \ + -e POSTGRES_PASSWORD=test \ + -it \ + -v ./postgres:/var/lib/postgresql/data \ + -p 0.0.0.0:5432:5432 \ + postgres:14 diff --git a/postgres/.gitkeep b/postgres/.gitkeep new file mode 100644 index 0000000..e69de29