Skip to content

Instantly share code, notes, and snippets.

View leifdenby's full-sized avatar
🌍

Leif Denby leifdenby

🌍
View GitHub Profile
@leifdenby
leifdenby / gist:6130043
Created August 1, 2013 09:56
Method for performing numpy vectorized integration of a function over a discrete range, at several points.
import numpy as np
def cellAverageIntegrator1D(f, x0, dx, N=10):
"""
This function calculates the integral of a given (numpy vectorized)
function f over the interval [x0-dx/2., x0+dx/2.]. The number of discrete
points may be set using N.
The argument x0 may be a numpy array of discrete points (e.g. cell-centers)
to evaluate the integral. Because everything is vectorized this function
@leifdenby
leifdenby / .procmailrc
Last active March 23, 2024 03:32
Forwarding emails to a Python script with procmail
:0Wc:
| env python mail_receiver.py
@leifdenby
leifdenby / settings.py
Created May 6, 2015 09:12
Python warnings: Disable printing the content of the line that caused a warning
# disable printing lines for warnings
old_warning_formatter = warnings.formatwarning
warnings.formatwarning = lambda message, category, filename, lineno, line=None: old_warning_formatter(message, category, filename, lineno, False)
@leifdenby
leifdenby / migration_loaddata.py
Last active December 9, 2020 19:28
Django function for loading fixtures which use the current migration state of the model
from django.core import serializers
import os
def loaddata(fixture_name, apps, ignorenonexistent=True):
"""
Loads migrations that work at current state of a model, in constrast to
`loaddata` which requires a fixture to have data matching the fields
defined in `models.py`.
@leifdenby
leifdenby / postfix-spam-and-virus-filtering.md
Last active February 24, 2020 14:58
Setting up Postfix with spam and virus filtering (FreeBSD)

Assumptions

  • Actual users on local system, not virtual users.
  • FreeBSD (at least v10)

Installation

  • postfix
  • dovecot2 (not version 1 as local delivery, LDA, doesn't appear to work correctly with postfix)
  • sieve support for dovecot2 (in FreeBSD the package is called pigeonhole)
@leifdenby
leifdenby / notebook.ipynb
Created July 13, 2018 09:49
xESMF - Input array is not F_CONTIGUOUS issue
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@leifdenby
leifdenby / taskchain.sh
Created November 6, 2018 14:31
Utility for chaining multiple dependent PBS submit scripts
# Utility function for chaining multiple PBS submit scripts
# Leif Denby 6/11/2018
#
# usage:
#
# 1. Create a file containing the individual steps, e.g.
#
# tasklist.sh:
# WALLCLOCK=00:15:00 ./run.sh example_run
# WALLCLOCK=00:15:00 ./run.sh analysis
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@leifdenby
leifdenby / filter_bibliography.py
Created June 10, 2020 09:47
Filter bibliography file based on citations used in tex document
# coding: utf-8
"""
Created a filtered .bib-file from citations used in a specific .tex source file
"""
import pybtex
import pybtex.database
import pybtex.errors
import re
@leifdenby
leifdenby / httpcors
Created January 16, 2021 13:13 — forked from gkatsev/httpcors
simple python3 http server with CORS enabled
#!/usr/bin/env python
import http.server
class CORSHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied