Skip to content

Instantly share code, notes, and snippets.

View evancauwenberg's full-sized avatar

Evert Van Cauwenberg evancauwenberg

View GitHub Profile
const path = require('path');
const fs = require('fs');
const { Transform } = require('stream');
const csv = require('fast-csv');
class PersistStream extends Transform {
constructor(args) {
super({ objectMode: true, ...(args || {}) });
this.batchSize = 100;
this.batch = [];
@evancauwenberg
evancauwenberg / keybase.md
Last active November 15, 2019 10:05
keybase.md

Keybase proof

I hereby claim:

  • I am evancauwenberg on github.
  • I am evancauwenberg (https://keybase.io/evancauwenberg) on keybase.
  • I have a public key ASCzpv8YmWy5nujDdH0kvpgB5aI7l6NG7nKzK_5prPrjEAo

To claim this, I am signing this object:

@evancauwenberg
evancauwenberg / remove_documents_mongodb.js
Created April 11, 2018 14:46 — forked from Stoffo/remove_documents_mongodb.js
Remove Documents older than x days in MongoDB
var date = new Date();
var daysToDeletion = 120;
var deletionDate = new Date(date.setDate(date.getDate() - daysToDeletion));
printjson(deletionDate);
var db = db.getSiblingDB('db')
db.getMongo().setSlaveOk();
printjson(db.messages.find({insertDate : {$lt : deletionDate}}).count());
_read() {
// // List all xml tags that have more than one child.
this.xmlStream.collect('title');
// // catch error
// this.xmlStream.on('error', console.log);
this.xmlStream.on(`updateElement: ${this.elementToExtract}`, (updateElement) => {
this.push(updateElement);
});
@evancauwenberg
evancauwenberg / Document.php
Created April 29, 2016 08:32 — forked from beberlei/Document.php
My Symfony2 File Upload workflow
<?php
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* @Entity
*/
class Document
{
@evancauwenberg
evancauwenberg / gist:cf533bbf7c7098399c91
Created March 22, 2016 09:59 — forked from tamoyal/gist:10441108
Create super user and database user in Mongo 2.6
# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile
layout title description tags
default
SQL Style Guide
A guide to writing clean, clear, and consistent SQL.
data
process

Purpose

@evancauwenberg
evancauwenberg / nth-biggest-product.php
Created January 28, 2016 09:55 — forked from Isinlor/lazy-consecutive-biggest-product.php
Get nth biggest product of two arrays
<?php
class IteratorsPriorityQueue extends SplPriorityQueue {}
function getNthIterator($n, $s, $nthA, $bList) {
for ($i=0; $i < $s; $i++) {
yield $nthA * $bList[$i];
}
}
@evancauwenberg
evancauwenberg / composer.json
Created January 15, 2016 09:39 — forked from jaytaph/composer.json
Using the Symfony security component as standalone
{
"name": "jaytaph/security-example",
"require": {
"symfony/security-core": "~2.8"
},
"authors": [
{
"name": "Joshua Thijssen",
"email": "jthijssen@noxlogic.nl"
}
@evancauwenberg
evancauwenberg / AppKernel.php
Created November 26, 2015 17:52 — forked from kbond/AppKernel.php
JWT Authentication With Symfony Guard. POST username/password to /login to receive token, /api* requests require a valid token
<?php
// app/AppKernel.php
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
class AppKernel extends Kernel
{
public function registerBundles()
{