Skip to content

Instantly share code, notes, and snippets.

@letmaik
letmaik / .travis.yml
Last active December 15, 2021 23:10
Deploy snapshots to Sonatype after Travis CI build
language: java
env:
global:
- SONATYPE_USERNAME=yourusername
- secure: "your encrypted SONATYPE_PASSWORD=pass"
after_success:
- python addServer.py
- mvn clean deploy --settings ~/.m2/mySettings.xml
@letmaik
letmaik / Example.java
Created June 25, 2013 09:42
Adds CellTable's Model support to a FlexTable (Google Web Toolkit)
package com.github.neothemachine.flextable.client;
import com.github.neothemachine.flextable.client.ModelFlexTable.FlexColumn;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
@letmaik
letmaik / voronoi_polygons.py
Last active June 9, 2022 22:16
Creates a Voronoi diagram with cell polygons using scipy's Delaunay triangulation (scipy >= 0.9)
from __future__ import division
import collections
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from scipy.spatial import Delaunay, KDTree
# an adaptation of https://stackoverflow.com/a/15783581/60982
# using ideas from https://stackoverflow.com/a/9471601/60982
@letmaik
letmaik / boundingbox.py
Last active August 29, 2015 13:56
Minimum bounding box for set of bounding boxes (longitude calculation)
import numpy as np
import numpy.ma as ma
# this is an implementation of:
# http://gis.stackexchange.com/questions/17788/how-to-compute-the-bounding-box-of-multiple-layers-in-lat-long/17987#17987
def minimumBoundingBox(lons):
xs = np.sort(lons.ravel())
xs = np.concatenate((xs,[xs[0]+360]))
@letmaik
letmaik / nssdc.py
Created February 12, 2014 18:19
Query the NSSDC Master Catalog for spacecrafts of certain disciplines
import urllib
import urllib2
import re
# To NSSDC: Please provide a REST API. Thanks.
class Discipline:
'''
as in http://nssdc.gsfc.nasa.gov/nmc/SpacecraftQuery.jsp form
'''
@letmaik
letmaik / masked_adaptive_threshold.py
Last active January 22, 2021 20:51
Adaptive threshold with masking (two versions)
from __future__ import division
import numpy as np
from scipy.ndimage.filters import correlate1d
def masked_adaptive_threshold(image,mask,max_value,size,C):
'''
image must already be masked (unmasked areas=0)
mask is a boolean array
see http://stackoverflow.com/a/10015315/60982
@letmaik
letmaik / models_committed.py
Created May 22, 2014 14:54
delete, insert, update events after a commit for SQLAlchemy
from sqlalchemy import create_engine, event, orm
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.session import Session as SessionBase, object_session
from sqlalchemy.event.api import listen
# The following adds delete, insert, and update events after successful commits.
# SQLAlchemy provides only events after flushes, but not after commits.
# The classes are adapted from Flask-SQLAlchemy.
# see also https://stackoverflow.com/a/12026787/60982
@letmaik
letmaik / histogram.py
Created June 29, 2014 11:39
Fast version of numpy histogram functions
'''
This module contains a fast replacement for numpy's histogramdd and histogram2d.
Two changes were made. The first was replacing
np.digitize(a, b)
with
np.searchsorted(b, a, "right")
@letmaik
letmaik / figimage.py
Created September 12, 2014 14:42
Draw things naturally onto an image using matplotlib
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
def loadFigImage(path):
im = mpimg.imread(path)
h,w = im.shape[0], im.shape[1]
dpi = 80
fig = plt.figure(figsize=(w/dpi, h/dpi), dpi=dpi)
ax = plt.Axes(fig, [0, 0, 1, 1])
ax.set_xlim(0, w)
@letmaik
letmaik / theme-37093.xml
Last active August 29, 2015 14:21
Eclipse Color Theme (Obsidian variation, esp. for Java)
<?xml version="1.0" encoding="utf-8"?>
<colorTheme id="37093" name="Obsidian Java" modified="" author="Maik">
<searchResultIndication color="#616161" />
<filteredSearchResultIndication color="#616161" />
<occurrenceIndication color="#616161" />
<writeOccurrenceIndication color="#616161" />
<findScope color="#E0E2E4" />
<deletionIndication color="#E0E2E4" />
<sourceHoverBackground color="#FFFFFF" />
<singleLineComment color="#7D8C93" />