Skip to content

Instantly share code, notes, and snippets.

@gearbox
gearbox / Concurrent simultaneous jobs.md
Created August 13, 2020 09:08
Use concurrent IO jobs for speed up

I am testing Postgres insertion performance. I have a table with one column with number as its data type. There is an index on it as well. I filled the database up using this query:

insert into aNumber (id) values (564),(43536),(34560) ...

I inserted 4 million rows very quickly 10,000 at a time with the query above. After the database reached 6 million rows performance drastically declined to 1 Million rows every 15 min. Is there any trick to increase insertion performance? I need optimal insertion performance on this project. Using Windows 7 Pro on a machine with 5 GB RAM.

@gearbox
gearbox / Exclude_tables.md
Last active June 4, 2020 23:28 — forked from utek/Exclude_tables.md
Define ignored tables in alembic.ini

Add this in your ini file:

[alembic:exclude]
tables = spatial_ref_sys

In env.py:

def exclude_tables_from_config(config_):
    tables_ = config_.get("tables", None)

if tables_ is not None:

@gearbox
gearbox / gist:f6a32b3b0d358389ca019a11c7b48dfb
Created April 30, 2020 08:41 — forked from joshuapowell/gist:e209a4dac5c8187ea8ce
Setup Postgres.app to use PostGIS on OS X

Download and Install Postgres.app

Before we can setup PostGIS we need to have a local version of Postgresql installed and running. The most effecient way to do this is to download and install Postgres.app.

Spatially Enable your Postgres Database

Once Postgres.app is installed in your computers /Applications directory. Open the Terminal and enter the following two commands

psql -d DATABASE_NAME -f /Applications/Postgres.app/Contents/Versions/9.3/share/postgresql/contrib/postgis-2.1/postgis.sql
@gearbox
gearbox / flask_ssl_app.py
Created April 4, 2020 18:42 — forked from vpack/flask_ssl_app.py
Flask SSL Sample APP
from flask import Flask
from flask_sslify import SSLify
"""
Option 1 : (pip install pyopenssl)
from OpenSSL import SSL
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('web.key')
context.use_certificate_file('web.crt')
@gearbox
gearbox / python_decorator_guide.md
Created February 22, 2020 23:31 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@gearbox
gearbox / bobp-python.md
Created August 3, 2019 22:47 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@gearbox
gearbox / sqlalchemy_app.py
Last active June 25, 2019 07:30 — forked from DmitryBe/app.py
SQLAlchemy quick start
# http://bytefish.de/blog/first_steps_with_sqlalchemy/
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from datetime import datetime, timedelta
from sqlalchemy import Table, Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.orm import relationship, backref
from sqlalchemy.orm import sessionmaker
Base = declarative_base()