Skip to content

Instantly share code, notes, and snippets.

Avatar

Christiaan Westerbeek christiaanwesterbeek

View GitHub Profile
@christiaanwesterbeek
christiaanwesterbeek / ra-data-postgraphile.ts
Last active Aug 26, 2019 — forked from alexkubica/dataProvider.ts
dataProvider adaptation for postgraphile flavor
View ra-data-postgraphile.ts
// from https://gist.github.com/ak-il/e91bfbd2c7c83086c7ded41512335795
import gql from 'graphql-tag';
import {
GET_LIST,
GET_ONE,
GET_MANY,
CREATE,
UPDATE,
DELETE,
} from 'react-admin';
View gist:277db6f04bd26d87d0f1b3c9a8552e1f
Q: En nu wil ik het naadje van de kous weten van Apollo in Express
A: https://www.robinwieruch.de/graphql-apollo-server-tutorial/
Q: Genereer een veilig token dat in een URL gebruikt kan worden
A: https://stackoverflow.com/questions/8855687/secure-random-token-in-node-js
```
const crypto = require('crypto')
const randomBytes = Util.promisify(crypto.randomBytes)
const plain = (await randomBytes(24)).toString('base64').replace(/\W/g, '')
```
@christiaanwesterbeek
christiaanwesterbeek / db.js
Created Jun 14, 2018
use a single mssql connection pool across several files using a promise
View db.js
const sql = require('mssql')
const config = {}
const pool = new sql.ConnectionPool(config)
.connect()
.then(connPool => {
console.log('Connected to MSSQL')
return connPool
})
.catch(err => console.log('Database Connection Failed! Bad Config: ', err))
@christiaanwesterbeek
christiaanwesterbeek / index.js
Last active May 15, 2018
Calculating and testing the last iso week of years
View index.js
import tape from 'tape'
import moment from 'moment'
const getLastIsoWeekOfYear = year =>
moment()
.isoWeek(30)
.isoWeekYear(year + 1)
.isoWeek(1)
.isoWeekday(1)
.add(-1, 'days')
@christiaanwesterbeek
christiaanwesterbeek / splitsAdres.js
Last active Oct 17, 2021
Splitsen van een nederlands adres naar straat, huisnummer en toevoeging middels een regular expression. Deutsch-Adressen werden jetzt auch unterstützt.
View splitsAdres.js
let re = /^(\d*[\wäöüß\d '\/\\\-\.]+)[,\s]+(\d+)\s*([\wäöüß\d\-\/]*)$/i
let adressen = [
'Dorpstraat 2',
'Dorpstr. 2',
'Laan 1933 2',
'18 Septemberplein 12',
'Kerkstraat 42-f3',
'Kerk straat 2b',
'42nd street, 1337a',
'1e Constantijn Huigensstraat 9b',
View get_barcode_from_image.js
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',