Skip to content

Instantly share code, notes, and snippets.

View claustres's full-sized avatar
🏠
Working from home

Luc Claustres claustres

🏠
Working from home
View GitHub Profile
@claustres
claustres / geospatial_operator_sift.js
Created December 10, 2019 14:06
Geospatial operator for sift
import memory from 'feathers-memory'
import intersect from '@turf/intersect'
// Create a sift filter supporting a geospatial operator
const matcher = (query) => sift(query, {
expressions: {
$geoIntersects: function(query, value) {
const polygon1 = _.get(query, '$geometry')
const polygon2 = value
if (!polygon1 || !polygon2) return false
@claustres
claustres / feathers_geospatial_query.js
Created December 10, 2019 13:55
Geospatial query on Feathers service
// Our geospatial services store GeoJson objects like this
const result = await app.service('service').create({
type: 'Polygon',
geometry: {
type: 'Polygon',
coordinates: [...]
},
properties: { ... }
})
@claustres
claustres / feathers_mocked_service.js
Created December 10, 2019 13:40
Feathers mocked service
const MockedService = require('feathers-memory')
// This is default fake data to test your service
const store = {
0: {
id: 0,
property: 'xxx'
}
}
// This will be the next available ID when creating new objects
const startId = 1
@claustres
claustres / kano_client.js
Created June 4, 2019 14:33
Kano feathers client
async main () {
// Initialize the sole client we need
await this.setupKano()
// Now we can transparently access Weacast API whenever required through the main app client
const response = await this.api.service('forecasts').find()
this.forecastModels = response.data
}
@claustres
claustres / kano_weacast_client.js
Last active June 4, 2019 14:28
Kano/Weacast feathers client
import config from 'config'
import feathers from '@feathersjs/client'
import reactive from 'feathers-reactive'
...
// Initialize a Feathers client with given options
async setupClient (options) {
let client = feathers()
// Initialize whatever you need based on your client config
if (options.websocket) client.configure(feathers.socketio(...))
@claustres
claustres / print_client_user_simulation.js
Last active June 27, 2018 07:36
Print client user simulation
import path from 'path'
import { PrintApp } from './page-model'
export const appUrl = process.env.APP_URL || 'http://kargo-www.s3-website.eu-central-1.amazonaws.com/'
let app = new PrintApp()
fixture`Print`// declare the fixture
.page`${appUrl}`
.afterEach(async test => {
@claustres
claustres / print_client_page_model.js
Created June 26, 2018 20:27
Print client page model for TestCafé
import { Selector } from 'testcafe'
export class PrintApp {
constructor () {
this.baseLayerMenu = Selector('.basemaps')
this.overlayLayerMenu = Selector('.leaflet-control-layers')
this.fileInput = Selector('input').withAttribute('type', 'file')
this.printMenu = Selector('#leafletEasyPrint')
}
async checkNoError (test) {
@claustres
claustres / aws_cognito_verifier.js
Created June 15, 2018 06:30
AWS Cognito FeathersJS Verifier
import makeDebug from 'debug'
import _ from 'lodash'
import { Verifier } from 'feathers-authentication-oauth2'
const debug = makeDebug('feathers-authentication-oauth2:verify')
class OAuth2Verifier extends Verifier {
constructor (app, options = {}) {
options.emailField = options.emailField || 'email'
options.emailFieldInProfile = options.emailFieldInProfile || ['email', 'emails[0].value']
@claustres
claustres / password_policy_hook.js
Last active May 18, 2018 20:17
Password policy with FeathersJS
import makeDebug from 'debug'
import { getItems } from 'feathers-hooks-common'
import { BadRequest } from 'feathers-errors'
const debug = makeDebug('debug')
export function enforcePasswordPolicy (options = {}) {
return async function (hook) {
if (hook.type !== 'before') {
throw new Error(`The 'enforePasswordPolicy' hook should only be used as a 'before' hook.`)
}
@claustres
claustres / password_policy_config.js
Last active May 18, 2018 17:05
Password policy with FeathersJS - Config
var path = require('path')
var fs = require('fs')
module.exports = {
host: process.env.HOSTNAME || 'localhost',
port: 8081,
authentication: {
secret: 'xxx',
strategies: [
'jwt',