Skip to content

Instantly share code, notes, and snippets.

View leplatrem's full-sized avatar

Mathieu Leplatre leplatrem

View GitHub Profile
@leplatrem
leplatrem / gist:5317450
Created April 5, 2013 08:02
Repair South and GeoModel fields SRID
find . -name "????_*.py" | xargs sed -i "s/from django.db import models/from django.db import models\nfrom django.conf import settings/"
find . -name "????_*.py" | xargs sed -i "s/'32632'/'%s' % settings.SRID/g"
find . -name "????_*.py" | xargs sed -i "s/srid=32632/srid=settings.SRID/g"
@leplatrem
leplatrem / yourapp
Last active September 24, 2023 23:01
gunicorn virtualenv init.d script (could be simpler with upstart)
#! /bin/bash
### BEGIN INIT INFO
# Provides: yourapp
# Required-Start: nginx
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: The main django process
# Description: The gunicorn process that receives HTTP requests
# from nginx
CREATE OR REPLACE FUNCTION SimplifyEdgeGeom(atopo varchar, anedge int, maxtolerance float8)
RETURNS float8 AS $$
DECLARE
tol float8;
sql varchar;
BEGIN
tol := maxtolerance;
LOOP
sql := 'SELECT topology.ST_ChangeEdgeGeom(' || quote_literal(atopo) || ', ' || anedge
|| ', ST_Simplify(geom, ' || tol || ')) FROM '
@leplatrem
leplatrem / geojson-collection
Created June 12, 2013 21:55
Daybed GeoJSON profile
* FeatureCollection
* Feature properties contains unique ``id`` field
@leplatrem
leplatrem / wmo2geojson.py
Last active December 4, 2023 13:01
Convert list of WMO weather stations to GeoJSON
import csv
import json
def dms2latlng(value):
"""
Degres Minutes Seconds to Decimal degres
"""
degres, minutes, seconds = value.split()
seconds, direction = seconds[:-1], seconds[-1]
@leplatrem
leplatrem / gist:6552003
Last active December 23, 2015 00:09
Auto-login middleware
from urlparse import urlparse
from django.conf import settings
from django.contrib.auth import get_user_model
User = get_user_model()
CONVERSION_SERVER_HOST = urlparse(settings.CONVERSION_SERVER).hostname
try:
@leplatrem
leplatrem / popup_home.html
Last active December 28, 2015 23:59
Popup example
<section>
<div class="header">
<img class="logo" src="/media/logo.png" alt="logo">
<h1>Rando, l'offre de randonnée pour découvrir le patrimoine du Parc.</h1>
</div>
<div class="row-fluid">
<div class="span4">
<a href="/#search" class="pjax profile">
<img src="/media/search.jpg" alt="logo">
<span class="caption">Recherche</span>
@leplatrem
leplatrem / mbtiles_split.py
Created January 14, 2014 09:38
Split a big MBTiles into smaller ones, based on column index
#!/usr/bin/env python
import os
import sys
import shutil
import subprocess
class UserError(Exception):
pass
@leplatrem
leplatrem / utils.py
Created April 11, 2014 12:40
Log models
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import force_unicode
from django.forms.models import model_to_dict
def log_addition(request, dbobject, oldobject=None, message=None):
_log_action(request, dbobject, oldobject, ADDITION, message)
@leplatrem
leplatrem / .gitconfig
Created November 19, 2014 13:51
Git config (exemple)
[user]
name = Your Name\n
email = you@email.com
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow