Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Eddie eddieajau

View GitHub Profile
@eddieajau
eddieajau / typeorm_model.ts
Last active May 9, 2019
Example of automatic translation of a JSON property in a TypeORM model.
View typeorm_model.ts
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;
View SafeObserver.ts
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 Mar 20, 2016
Module to allow a Sequelize select query to be converted into a stream.
View createSequelizeStream.js
"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 Aug 3, 2015
Waterline validation error
View waterline-error.md
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
NPM Package Scripts
View package.json
{
"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 Dec 16, 2014
Clean architecture for basic entity CRUD in Node.
View Collection.js
/**
* 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 Aug 12, 2014
Extract a column from an array of JavaScript objects.
View extractColumn.js
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 Dec 31, 2015
Joomla Framework Release Strategy
View fw_release_strategy.md

Joomla! Framework Release Strategy

1. Introduction

1.1 Revision History

Version Date Notes
1.0.0 16 December 2013 First version
View DataMapper.php
<?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;
@eddieajau
eddieajau / test.php
Created Mar 11, 2013
A strategy for mocking a PSR-3 logger. This assume the class being tested has a `log` method which probably checks if the logger has been set and then proxies to `$this->logger->log`.
View test.php
use Psr\Log;
class TheTest extends \PHPUnit_Framework_TestCase
{
/**
* The class we are testing.
*/
protected $instance;
/**
You can’t perform that action at this time.