Skip to content

Instantly share code, notes, and snippets.

View digitalsadhu's full-sized avatar

Richard Walker digitalsadhu

View GitHub Profile
function sum(a, b) {
return a + b;
}
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
it('should add 1 + 2 and return 3', () => {
expect(sum(1, 2)).toBe(3);
@digitalsadhu
digitalsadhu / ash-model-design.md
Created January 20, 2017 10:30
Ash model design

Models

Defining a model

class Post extends Model {
  static attributes (attr) {
    attr('title', 'string')
    attr('description', 'string')
 }
@digitalsadhu
digitalsadhu / propsed-ash-orm-levels.md
Created January 19, 2017 21:31
Proposal for ORM data access options

3 layers of data access (proposal)

Model methods: (layer 3)

These mirror ember data methods. They are high level and aim to be useable by the API via the url query string etc. They follow jsonapi spec where appliable. They are:

findAll

This file has been truncated, but you can view the full file.
<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Media Releases</title>
<link>http://www.nzta.govt.nz/media-releases/rss</link>
<atom:link href="http://www.nzta.govt.nz/media-releases/rss" rel="self" type="application/rss+xml" />
<description></description>
<item><title>Wellington highways closed due to surface flooding - update 11.45am</title><link>http://www.nzta.govt.nz/media-releases/wellington-highways-closed-due-to-surface-flooding-update-11-45am</link><pubDate>2016-11-15 11:45:00</pubDate><guid>http://www.nzta.govt.nz/media-releases/wellington-highways-closed-due-to-surface-flooding-update-11-45am</guid><description></description><category>Media release</category><category>Central</category></item>
var findContract = _.flip(_.wrapCallback(Contract.findById.bind(Contract)), {remoteCtx: ctx});
var findContractPeriods = _.flip(_.wrapCallback(ContractPeriod.find.bind(ContractPeriod)), {remoteCtx: ctx});
var findContractPeriod = _.flip(_.wrapCallback(ContractPeriod.findById.bind(ContractPeriod)), {remoteCtx: ctx});
var findReviews = _.flip(_.wrapCallback(Review.find.bind(Review)), {remoteCtx: ctx});
var sendEmail = _.wrapCallback(sendReminderEmail);
var contractPeriodStream1 = findReviews(query).flatten().pluck('contractPeriodId').map(findContractPeriod);
var contractPeriodStream2 = findContractPeriods(query).flatten();
contractPeriodStream1.merge(contractPeriodStream2)
@digitalsadhu
digitalsadhu / leaflet-snap-example.js
Last active August 29, 2015 14:07
Leaflet, leaflet snap and some snippity dippity
/**
* Requires leaflet
* Requires leaflet-geometryutil plugin loaded
* Requires leaflet-snap plugin loaded
*/
//geojson guide layer, this is a linestring around the old town hall
var guideLayer = L.geoJson({
"type": "FeatureCollection",
"features": [
@digitalsadhu
digitalsadhu / augment-geojson-data.js
Created October 6, 2014 13:42
Intersects geojson features with a POSTGIS database
#!/usr/bin/env node
'use strict';
var through = require('through2')
, geojsonStream = require('geojson-stream')
, fs = require('fs')
, chalk = require('chalk')
, pg = require('pg')
@digitalsadhu
digitalsadhu / tmps-to-postgis.js
Created October 6, 2014 13:36
Inserts TMP data into a POSTGIS database
#!/usr/bin/env node
'use strict';
var pg = require('pg')
, geojsonStream = require('geojson-stream')
, fs = require('fs')
, stdout = require('stdout-stream')
, through2 = require('through2')
, Q = require('q')
@digitalsadhu
digitalsadhu / osm-geojson-to-2-node-ways.js
Created October 6, 2014 13:31
Script to convert osm geojson data to osm ways geojson feature pairs
#!/usr/bin/env node
'use strict';
//Streaming parser that filters out osm data leaving just ways.
//Ways are then broken down into node pairs.
//
//ie.
//{
// "type":"Feature",
@digitalsadhu
digitalsadhu / gist:1c1798536e9b726c548d
Last active December 15, 2020 07:10
Installing postgis on mac
# installation commands
brew update
brew install postgresql
brew install postgis
# start the server
postgres -D /usr/local/var/postgres
# setup commands
createdb <name>