Skip to content

Instantly share code, notes, and snippets.

View dokterbob's full-sized avatar

Mathijs de Bruin dokterbob

View GitHub Profile
@dokterbob
dokterbob / ipfs-robust-add.sh
Last active September 15, 2023 12:18
Add arbitrarily large directory structures to IPFS, without running into OOM kills, failure at 99% etc.
#!/bin/sh
set -e # Enable errexit option
### Adding arbitrarily large directory structures to IPFS, without running into OOM kills, failure at 99% etc.
### Results in directory with same name in MFS, use `ipfs files ls` to see it.
### Uses Blake2B for faster hashing and maximum block size, assuming large fiels with lower needs for searching.
### Uses filestore as not to duplicate data (make sure to enable it in the ipfs config!).
# Create directory structure in MFS
@dokterbob
dokterbob / admin.py
Created February 15, 2011 20:00
InlineAdmin mixin limiting the selection of related items according to criteria which can depend on the current parent object being edited.
class LimitedAdminInlineMixin(object):
"""
InlineAdmin mixin limiting the selection of related items according to
criteria which can depend on the current parent object being edited.
A typical use case would be selecting a subset of related items from
other inlines, ie. images, to have some relation to other inlines.
Use as follows::
@dokterbob
dokterbob / validators.py
Created May 30, 2011 10:58
Validator which allows for relative URL's as well. Based on Django's URLValidator.
import platform
import re
import urllib2
import urlparse
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.core.urlresolvers import resolve
from django.http import Http404
from django.utils.translation import ugettext_lazy as _
@dokterbob
dokterbob / fields.py
Created March 18, 2011 19:07
Email field with domain existence validation for Django.
import logging
logger = logging.getLogger(__name__)
# Note: we need dnspython for this to work
# Install with `pip install dnspython`
import dns.resolver, dns.exception
from django import forms
from django.utils.translation import ugettext as _
@dokterbob
dokterbob / validators.py
Created August 31, 2011 15:03
Validator for files, checking the size, extension and mimetype.
from os.path import splitext
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import filesizeformat
class FileValidator(object):
"""
Validator for files, checking the size, extension and mimetype.
@dokterbob
dokterbob / avalanchego_on_smartos.md
Created March 26, 2021 14:57
Building avalanchego on SmartOS
@dokterbob
dokterbob / next_previous.py
Created June 2, 2011 10:19
Django template tag to efficiently get the next or previous object in the Django queryset, with regards to the item specified.
from django import template
register = template.Library()
from templatetag_sugar.register import tag
from templatetag_sugar.parser import Constant, Variable, Name
from .utils import get_next_or_previous
"""
Efficient and generic get next/previous tags for the Django template language,
@dokterbob
dokterbob / autoslug.py
Created February 15, 2011 18:46
Mixins for automatically setting (unique) slugs for Django models -- also using values from inline classes.
from django.template.defaultfilters import slugify
class AutoSlugMixin(object):
"""
Automatically set slug to slugified version of the name if left empty.
Use this as follows::
class MyModel(AutoSlugMixin, models.Model):
def save(self):
super(MyModel, self).save()
@dokterbob
dokterbob / build.sh
Last active May 24, 2019 20:26
SAGA 7.2 build on macOS Mojave 10.14.5
#!/bin/sh
./configure \
--with-gdal=/Library/Frameworks/GDAL.framework/Versions/2.4/unix/bin/gdal-config \
--disable-odbc \
CXXFLAGS="-std=gnu++11" \
CPPFLAGS="-I/Library/Frameworks/PROJ.framework/Headers" \
LDFLAGS="-L/Library/Frameworks/PROJ.framework/unix/lib"
make -j8
@dokterbob
dokterbob / README.rst
Last active August 13, 2018 00:47
Setting up a Mac system for Python.
  1. Install XCode from the App Store.
  2. Install the XCode command line tools from the 'Downloads' pane in the XCode settings.
  3. Install SublimeText.
  4. Add the following SublimeText configuration options (to User settings):

    // Set to true to insert spaces when tab is pressed
    "translate_tabs_to_spaces": true,