Skip to content

Instantly share code, notes, and snippets.

View dbazile's full-sized avatar

David Bazile dbazile

View GitHub Profile
@dbazile
dbazile / README.md
Last active September 12, 2015 00:49
Example phpunit test

Here I wrote a quick example test and I removed that junk from the run script. Please make sure your phpunit.bat looks like the one on this page.

Then, you should be able to run it with the command:

\php\phpunit\phpunit.bat name_of_test_file.php

For more information, here's a link to much better documentation than I could provide: https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html

Good luck and sorry about the bad info!

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dbazile
dbazile / Coordinate.js
Created June 7, 2016 01:37
Super old coordinate utility thingy I needed way back when.
/**
* Coordinate.js
*
* Utility for performing on-the-fly coordinate conversion
*/
(function($, geo) {
var Coordinate,
CoordinateTextbox,
pad = function(input, depth) { return ("0000000000" + input).slice(-depth); },
@dbazile
dbazile / pagination.js
Created June 13, 2016 16:32
Because looking it up every time is a PITA
export function paginate({startIndex, count, totalCount}) {
return {
page: Math.ceil(startIndex / count),
pages: Math.ceil(totalCount / count)
}
}
const canvas = document.querySelector('canvas')
const context = canvas.getContext('2d')
const LIGHTNESS_THRESHOLD = 1
const image = new Image()
image.crossOrigin = 'Anonymous'
image.addEventListener('load', () => {
context.drawImage(image, 0, 0, canvas.width, canvas.height)
import {CancelablePromise} from './CancelablePromise'
export function fetchThumbnail(url) {
const cancelable = new CancelablePromise((resolve, reject) => {
const thumbnail = new Image()
thumbnail.crossOrigin = 'Anonymous'
thumbnail.onload = () => resolve(thumbnail)
thumbnail.onerror = () => reject(new Error(`fetch failed (url=${url})`))
thumbnail.src = url
})
const WGS84: ol.proj.ProjectionLike = 'EPSG:4326'
const WEB_MERCATOR: ol.proj.ProjectionLike = 'EPSG:3857'
function getDatelineAwareExtent(geometry: ol.geom.Geometry) {
if (geometry instanceof ol.geom.MultiPolygon && crossesDateline(geometry)) {
const extents = geometry.getPolygons().map(g => ol.proj.transformExtent(g.getExtent(), WEB_MERCATOR, WGS84))
let [, minY, , maxY] = ol.proj.transformExtent(geometry.getExtent(), WEB_MERCATOR, WGS84)
let width = 0
let minX = 180
for (const [polygonMinX, , polygonMaxX] of extents) {
SELECT ST_AsText(ST_GeomFromGeoJSON(fc.features->>'geometry')) AS geometry,
row_number() OVER () AS feature_id
FROM (SELECT json_array_elements('{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
},
from time import time
from PIL import Image, ImageDraw
def by_geometry_mask():
def to_percentage(coordinates, extent):
min_x, min_y, max_x, max_y = extent
points = []
for x, y in coordinates:
px = (x - min_x) / (max_x - min_x)