Skip to content

Instantly share code, notes, and snippets.

View NicholasTurner23's full-sized avatar
💭
I may be slow to respond.

Nicholas Bob NicholasTurner23

💭
I may be slow to respond.
  • kampala, Uganda
View GitHub Profile
@ellisvalentiner
ellisvalentiner / bulk-insert.py
Last active January 10, 2023 19:03
Recipe for (fast) bulk insert from python Pandas DataFrame to Postgres database
#!/usr/bin/env/python
import psycopg2
import os
from io import StringIO
import pandas as pd
# Get a database connection
dsn = os.environ.get('DB_DSN') # Use ENV vars: keep it secret, keep it safe
conn = psycopg2.connect(dsn)
@fleepgeek
fleepgeek / apps.py
Last active September 10, 2024 20:50
A Django Middleware to prevent multiple sessions for the same user. It automatically logs out the previous session and replaces it with the new session.
from django.apps import AppConfig
class ForumConfig(AppConfig):
name = 'forum'
# This function is the only new thing in this file
# it just imports the signal file when the app is ready
def ready(self):
import your_app_name.signals