Skip to content

Instantly share code, notes, and snippets.

View christiaanwesterbeek's full-sized avatar

Christiaan Westerbeek christiaanwesterbeek

View GitHub Profile
/*
* 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',
@christiaanwesterbeek
christiaanwesterbeek / splitsAdres.js
Last active November 24, 2023 10:53
Splitsen van een nederlands adres naar straat, huisnummer en toevoeging middels een regular expression. Deutsch-Adressen werden jetzt auch unterstützt.
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',
@christiaanwesterbeek
christiaanwesterbeek / index.js
Last active May 15, 2018 10:12
Calculating and testing the last iso week of years
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 / db.js
Created June 14, 2018 06:13
use a single mssql connection pool across several files using a promise
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))
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 / ra-data-postgraphile.ts
Last active August 26, 2019 03:42 — forked from alexkubica/dataProvider.ts
dataProvider adaptation for postgraphile flavor
// 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';