Initial commit

This commit is contained in:
Shane Engelman 2023-07-30 20:49:44 -04:00
commit 51c8b33ca0
Signed by: shane
GPG Key ID: D9DF703B83B9A9B5
5 changed files with 75 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
postgres/

46
README.md Normal file
View File

@ -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
```

19
mock/insert_into.py Executable file
View File

@ -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()

8
mock/postgres.sh Executable file
View File

@ -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

0
postgres/.gitkeep Normal file
View File