Skip to content

Instantly share code, notes, and snippets.

@dustinsgoodman
dustinsgoodman / UserModel.js
Created November 27, 2020 18:42
Webpack + Lambda Issue - ES6 UserModel as ES6 Module
export default class UserModel {
constructor (data) {
Object.entries(data).forEach(([key, value]) => {
this[key] = value;
});
}
async update(data) {
Object.entries(data).forEach(([key, value]) => {
this[key] = value;
@dustinsgoodman
dustinsgoodman / UserModel.js
Created November 27, 2020 18:39
Webpack + Lambda Issue - ES6 UserModel without statics
import UserRepo from 'Repos/UserRepo';
export default class UserModel {
constructor (data) {
Object.entries(data).forEach(([key, value]) => {
this[key] = value;
});
}
async update(data) {
@dustinsgoodman
dustinsgoodman / UserModel.js
Last active November 27, 2020 18:39
Webpack + Lambda Issue - ES6 UserModel Class
import UserRepo from 'Repos/UserRepo';
export default class UserModel {
static async getByIds(ids) {
const users = UserRepo.getByIds(ids);
return users.map((user) => new this(user));
}
static async getById(id) {
const user = UserRepo.getById(id);
@dustinsgoodman
dustinsgoodman / output.txt
Created November 22, 2020 19:21
Serverless Webpack Issues - Heap Error
> serverless deploy -s dev
Serverless Plugin Error --------------------------------------
Cannot convert undefined or null to object
Serverless: WarmUp: setting 2 lambdas to be warm
Serverless: WarmUp: user-api-dev-**************
Serverless: WarmUp: user-api-dev-**************
Serverless: Bundling with Webpack...
<--- Last few GCs --->
[438:0x39908e0] 149226 ms: Mark-sweep 1768.9 (2060.1) -> 1768.9 (2045.9) MB, 571.1 / 0.0 ms (average mu = 0.168, current mu = 0.000) allocation failure GC in old space requested
[438:0x39908e0] 150360 ms: Mark-sweep 1795.9 (2072.9) -> 1753.4 (2060.1) MB, 972.4 / 0.0 ms (average mu = 0.153, current mu = 0.143) allocation failure GC in old space requested
@dustinsgoodman
dustinsgoodman / MyObjectDAO.php
Last active November 22, 2020 17:26
PHP Cache Blog - Mistake 2
<?php
namespace MyObject;
use Utils\ArrayUtils as _; // basically lodash
class DAO extends \Base\MySQL\DAO {
// ...
/**
* Lookup MyObject entities by relationship A. Can additionally filter by relationship B OR C.
@dustinsgoodman
dustinsgoodman / MyObjectDAO.php
Last active November 22, 2020 17:10
PHP Cache Blog - Mistake 1
<?php
namespace MyObject;
use Utils\ArrayUtils as _; // basically lodash
class DAO extends \Base\MySQL\DAO {
// ...
/**
* Lookup MyObject entities by relationship A. Can additionally filter by relationship B OR C.
@dustinsgoodman
dustinsgoodman / MyObjectDAO.php
Last active November 22, 2020 17:11
PHP Cache Blog - Original Problem
<?php
namespace MyObject;
use Utils\ArrayUtils as _; // basically lodash
class DAO extends \Base\MySQL\DAO {
// ...
/**
* Lookup MyObject entities by relationship A. Can additionally filter by relationship B OR C.
@dustinsgoodman
dustinsgoodman / mistake1.php
Last active November 22, 2020 16:30
How I managed to encounter and recover from Computer Science's Two Hardest Problems Snippets
<?php
namespace MyObject;
use Utils\ArrayUtils as _; // basically lodash
class DAO extends \Base\MySQL\DAO {
// ...
/**
* @param int|int[] $relationAId
@dustinsgoodman
dustinsgoodman / keybase.md
Last active August 18, 2016 16:49
keybase.md

Keybase proof

I hereby claim:

  • I am dustinsgoodman on github.
  • I am dgoodman (https://keybase.io/dgoodman) on keybase.
  • I have a public key whose fingerprint is 9D83 9A3E 86A5 2B05 38AD 9BA5 8C59 B2D2 BD6D 05E6

To claim this, I am signing this object:

@dustinsgoodman
dustinsgoodman / PythonIO2.py
Created May 12, 2013 20:09
An example of some more advanced I/O features in Python.
#Example 1: parsing each line of a file using read and string splitting
f = open("/home/sharocko/Documents/Codecademy/output.txt", "r") #open a test file with read mode
data = f.read() #read data from the file and store to a variable data
data = data.split('\n') #split the string on new lines
for line in data: #iterate each line of the string
print line.upper() #just print the upper case version of each line
f.close() #remember to close the file when you finish
#Example 2: using readline() to read data from a file
f = open("/home/sharocko/Documents/Codecademy/output.txt", "r")