Skip to content

Instantly share code, notes, and snippets.

Avatar

Melvyn Sopacua melvyn-sopacua

View GitHub Profile
@melvyn-sopacua
melvyn-sopacua / getwoonplaatsen.py
Last active Sep 26, 2017
Get all cities in The Netherlands using official dataset and merge them into a single GML file.
View getwoonplaatsen.py
import argparse
import os
import sys
import warnings
import requests
from lxml import etree
MAX_COUNT = 1000
MAX_RESULTS = 2501 # hardcoded to save us doing parsing of numberMatched
@melvyn-sopacua
melvyn-sopacua / fields.py
Created Jun 23, 2017
Inline form for a foreign key
View fields.py
from django.contrib.gis.db import models
from django.db.models.fields.related import (ForeignObject,
ForwardManyToOneDescriptor)
from .models import Address
def get_address(value: (Address, int, dict, None)) -> (Address, int, None):
if value is None:
return None
@melvyn-sopacua
melvyn-sopacua / forms.py
Created Mar 8, 2017
Case for pre_init form hook
View forms.py
from uuid import uuid4
from django.db.models import Model
from django.forms import BaseForm
__all__ = (
'WrappedForm',
)
@melvyn-sopacua
melvyn-sopacua / mixins.py
Created Mar 5, 2017
Display update form in a modal with initial data
View mixins.py
from django.views import generic
from django.db.models.base import Model
from collections import OrderedDict
from django.forms import BaseForm
from django.core.validators import RegexValidator
__all__ = (
'AdditionalFormsMixin',
)
@melvyn-sopacua
melvyn-sopacua / freebsd-port-build.sh
Last active Feb 15, 2017
Script to test a cmake build of a port from it's git checkout
View freebsd-port-build.sh
#!/bin/sh
WRKDIR=/usr/obj/ports/usr/ports/astro/nominatim/work
WRKSRC=$(realpath .)
BUILD_DIR="${WRKDIR}/.build"
MAKE=$(which gmake)
MAKE_JOBS=${MAKE_JOBS:-"2"}
CONFIGURE_ARGS="-DWWW_PUBLIC:PATH=/usr/local/www/nominatim -DWWW_APP:PATH=/usr/local/share/nominatim"
rm -rf ${BUILD_DIR}
mkdir -p ${BUILD_DIR}
@melvyn-sopacua
melvyn-sopacua / models.py
Created Feb 14, 2017
Calculated fields example
View models.py
from django.db import models
from django.db.models.signals import post_init
from django.db.models.fields import NOT_PROVIDED
from django.core import validators as v
class Substance(models.Model):
name = models.CharField(max_length=32, primary_key=True)
@melvyn-sopacua
melvyn-sopacua / mezzanine.patch
Created Jan 26, 2017
Fix Mezzanine 4.2.2 on Django 1.10+ with modeltranslation
View mezzanine.patch
--- ./pages/models.py.orig 2016-09-08 03:02:33.000000000 +0200
+++ ./pages/models.py 2017-01-26 23:26:16.672548649 +0100
@@ -18,6 +18,7 @@
from mezzanine.pages.fields import MenusField
from mezzanine.pages.managers import PageManager
from mezzanine.utils.urls import path_to_slug
+from mezzanine.core.models import wrapped_manager
class BasePage(Orderable, Displayable):
@melvyn-sopacua
melvyn-sopacua / archivers_libarchive.patch
Created Nov 15, 2016
Patch for archivers/libarchive to work with security/openssl-devel
View archivers_libarchive.patch
From dcb7b18f53289861af3b540723c759372777f60f Mon Sep 17 00:00:00 2001
From: Melvyn Sopacua <noreply@github.com>
Date: Tue, 15 Nov 2016 12:07:35 +0100
Subject: [PATCH] Fix port to build with openssl-devel:
* Do some macro hacking to rework *_init(ctx) to ctx = *_new() caused by
making (most) types Opaque
* libmd(3) will now be used for generic hashing functions
* -lcrypto has to be added since CRYPTO_CHECK(*, openssl, *) now fails
* Temporarily set PATCH_STRIP to allow git patches to apply cleanly
@melvyn-sopacua
melvyn-sopacua / sync-media.sh
Created Oct 5, 2015
Synchronize media to staging on hypernode without diskspace impact
View sync-media.sh
#!/bin/sh
_me=`basename $0`
_prod_root='/data/web/public'
_stage_root='/data/web/staging'
_wp_subdir='blog'
_wp_imageroot=''
[ ! -z "${_wp_subdir}" ] && _wp_imageroot="${_wp_subdir}/wp-content/uploads"
echo "Synchronizing media to staging (${_stage_root})"
View PATCH_SUPEE-3176_EE_1.13.0.1_v1.sh
#!/bin/bash
# Patch apllying tool template
# v0.1.2
# (c) Copyright 2013. Magento Inc.
#
# DO NOT CHANGE ANY LINE IN THIS FILE.
# 1. Check required system tools
_check_installed_tools() {
local missed=""