Skip to content

Instantly share code, notes, and snippets.

@eddieajau
eddieajau / csv-parse-async.mjs
Last active April 11, 2023 01:09
Parsing a CSV using a stream pipeline (async)
import { parse } from 'csv-parse'
import fs from 'fs'
import { pipeline } from 'stream/promises'
/**
* Do something async with a row.
*
* @param {*} row A row of the CSV as an object.
*/
async function handleRow(row) {
@eddieajau
eddieajau / typeorm_model.ts
Last active May 9, 2019 02:49
Example of automatic translation of a JSON property in a TypeORM model.
import { PrimaryGeneratedColumn, Entity, Column } from 'typeorm';
@Entity('foo')
export class Foo {
@PrimaryGeneratedColumn()
public id: number;
@Column({ default: '' })
public get link(): string {
let value = this._link;
class SafeObserver {
constructor(private _next: (value: any) => void = () => {},
public error: (errorValue: any) => void = (e: any) => { throw e; },
private _complete: (completeValue?: any) => void = () => {}) {}
public next(value: any) {
try {
this._next(value);
}
catch (e) {
@eddieajau
eddieajau / createSequelizeStream.js
Created March 20, 2016 22:14
Module to allow a Sequelize select query to be converted into a stream.
"use strict";
var Readable = require('stream').Readable;
/**
* Create a stream from batching a Sequelize select query.
*
* @param {Function} query - Function that returns a promise.
* @param {object} options
* @param {number} options.limit - The limit for the number of rows to return in each "batch"
@eddieajau
eddieajau / waterline-error.md
Created August 3, 2015 23:23
Waterline validation error
model.create(someData)
  .catch(function (err) {
    console.error('ValidationError:', err.ValidationError);
    console.error('Message:', err.message);
  });

Outputs:

ValidationError: {
@eddieajau
eddieajau / package.json
Created May 25, 2015 00:01
NPM Package Scripts
{
"devDependencies": {
"app-root-path": "^1.0.0",
"jshint": "^2.7.0",
"mocha": "^2.2.5",
"supertest": "^1.0.1"
},
"scripts": {
"check": "npm outdated",
"lint": "node_modules/.bin/jshint lib/ test/",
@eddieajau
eddieajau / Collection.js
Created December 16, 2014 00:51
Clean architecture for basic entity CRUD in Node.
/**
* Collection Interface.
*
* Concrete implementations would exist INSIDE the boundary interfaces.
*
* - Must be able to add one or more entities to the collection.
* - Must be able to find entities in the collection.
* - Must be able update entities in the collection.
* - Must be able to remove entities from the collection.
*
@eddieajau
eddieajau / extractColumn.js
Created August 12, 2014 23:49
Extract a column from an array of JavaScript objects.
function extractColumn(arr, column) {
function reduction(previousValue, currentValue) {
previousValue.push(currentValue[column]);
return previousValue;
}
return arr.reduce(reduction, []);
}
@eddieajau
eddieajau / fw_release_strategy.md
Last active December 31, 2015 11:59
Joomla Framework Release Strategy

Joomla! Framework Release Strategy

1. Introduction

1.1 Revision History

Version Date Notes
1.0.0 16 December 2013 First version
@eddieajau
eddieajau / DataMapper.php
Created December 2, 2013 21:44
Data mappers
<?php
/**
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Data;
use Psr\Cache\CacheInterface;