Skip to content

Instantly share code, notes, and snippets.

@tschaub
tschaub / split.js
Created May 4, 2012 14:21
quick implementation of polygon splitting process
// Execute method for js:split process expects polygon and line geometries as input
run: function(inputs) {
var merger = new LineMerger();
merger.add(inputs.poly._geometry);
merger.add(inputs.line._geometry);
var collection = merger.getMergedLineStrings();
var union = new UnaryUnionOp(collection).union();
var polygonizer = new Polygonizer();
polygonizer.add(union);
@tschaub
tschaub / gist:2722957
Created May 18, 2012 03:17
Git autocomplete and branch in PS1
# Set git autocompletion and PS1 integration
if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then
. /usr/local/git/contrib/completion/git-completion.bash
fi
PS1="\h:\W\$(__git_ps1)$ "
@tschaub
tschaub / gist:3091573
Created July 11, 2012 16:32
modify existing issue or pull request
# examples assume username is johndoe and johndoe has a branch named new-features
# these examples work with the openlayers organization and the ol3 repo, could be any other
# say you want to turn issue #5 into a pull request based on new-features branch
# same syntax if issue #5 is already a pull request
curl -d '{"issue": "5", "head": "johndoe:new-features", "base": "master"}' -u 'johndoe' https://api.github.com/repos/openlayers/ol3/pulls

API

Firstly, without any HPI helper functions, the API currently looks like this:

    var map = new ol.Map(document.getElementById('map'));
    var layer = ol.Layer.createOpenStreetMap({opacity: 0.5});
    map.getLayers().push(layer);

Adding a few flexibly-typed helper functions and some combined

@tschaub
tschaub / Range.java
Created August 8, 2012 02:05
Example of a JavaScript iterator created with Rhino.
/**
* Demonstrates how a JavaScript iterator can be created with Rhino. This
* simple Range class can be defined as a JavaScript constructor.
*
* Example use:
*
* >> // set up Range constructor and prototype
* >> defineClass(Packages.com.example.Range)
*
* >> var range = new Range(3, 5)
@tschaub
tschaub / make-pull.sh
Created October 24, 2012 17:23
Use httpie to turn a GitHub issue into a pull request
http -a <your-username> POST https://api.github.com/repos/<remote-user>/<repo-name>/pulls issue=<issue-number> head=<your-username>:<your-branch> base=master
@tschaub
tschaub / fly.js
Created November 8, 2012 16:35
example using animation-frame branch
var layer = new ol.layer.TileLayer({
source: new ol.source.MapQuestOpenAerial()
});
var map = new ol.Map({
center: new ol.Coordinate(0, 0),
layers: new ol.Collection([layer]),
renderer: ol.RendererHint.DOM,
target: 'map',
zoom: 2
@tschaub
tschaub / time-series.sql
Created December 4, 2012 06:23
Time series generator in psql
/**
Time series generator. This generates a series of times (as seconds since
the epoch) between any two start and end time values (also seconds since
the epoch). The $1 value can be 'second', 'minute', 'hour', 'day', 'week', or
'month'. The $2 and $3 values are start and end time respectively (in seconds
since the epoch.
*/
select date_part('epoch', date_trunc($1, to_timestamp($2)) + concat(tmp.index, $1)::interval) as time from generate_series(
0,
case
@tschaub
tschaub / mongo-mr.js
Created January 16, 2013 04:40
Mongo map-reduce experiments
function mapFunc() {
var i, ii, key, doc, service;
for (i = 0, ii = this.resources.length; i < ii; ++i) {
key = this.resources[i];
doc = {
services: {}
};
service = this.service || '';
doc.services[service] = 1;
emit(key, doc);
@tschaub
tschaub / synthetic-data.js
Created May 21, 2013 05:20
Rendering synthetic data with the canvas renderer.
goog.require('ol.Feature');
goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.View2D');
goog.require('ol.geom.Point');
goog.require('ol.layer.TileLayer');
goog.require('ol.layer.Vector');
goog.require('ol.parser.GeoJSON');
goog.require('ol.projection');
goog.require('ol.source.MapQuestOpenAerial');