Skip to content

Instantly share code, notes, and snippets.

View rbeucher's full-sized avatar

Romain Beucher rbeucher

View GitHub Profile
@rbeucher
rbeucher / django-shell-notebook-setup.md
Created May 14, 2019 11:59 — forked from madyasiwi/django-shell-notebook-setup.md
Guide to setup Django-shell Jupyter notebook running in Docker container

Setting Up Django-Shell Jupyter Notebook in Docker Container

This guide assumes that your django application already running in the container.

1. Install required python packages

You will have to make sure that django-extensions and jupyter packages are installed in the container's python virtual environment.

If you need to shell into the container as root user to do this, you can do so from the host PC:

@rbeucher
rbeucher / FK.py
Created May 14, 2019 11:06 — forked from Attila03/FK.py
Django bulk insert with Foreign Key
from stocks import wsgi
from django.core.exceptions import ObjectDoesNotExist
from api.models import Stock, Company
import csv
csvpath = r'prices.csv'
batch_size = 500
t1 = time.time()

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

Empty file just for gist title
def inside_polygon(x, y, points):
"""
Return True if a coordinate (x, y) is inside a polygon defined by
a list of verticies [(x1, y1), (x2, x2), ... , (xN, yN)].
Reference: http://www.ariel.com.au/a/python-point-int-poly.html
"""
n = len(points)
inside = False
p1x, p1y = points[0]
@rbeucher
rbeucher / gist:4524c7edec124d68da3d419d0266cbf3
Created March 5, 2018 10:53 — forked from simonw/gist:7000493
How to use custom Python JSON serializers and deserializers to automatically roundtrip complex types.
import json, datetime
class RoundTripEncoder(json.JSONEncoder):
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
"_type": "datetime",
"value": obj.strftime("%s %s" % (
@rbeucher
rbeucher / Makefile
Last active August 29, 2015 14:26 — forked from andrewharvey/Makefile
Download and index 250k scanned geological maps from Geoscience Australia
## About
# This script will download the maps and associated meta data for 250k
# Geological Maps at http://www.geoscience.gov.au/geoportal-geologicalmaps/
#
# Running `make all` shall suffice to run this script.
# ## License
# This script is licensed CC0 by Andrew Harvey <[email protected]>
#
# To the extent possible under law, the person who associated CC0