Skip to content

Instantly share code, notes, and snippets.

View elliotttf's full-sized avatar

Elliott Foster elliotttf

View GitHub Profile
@elliotttf
elliotttf / README.md
Last active August 12, 2021 15:00
Bench Memoization

Memo-what?

Memoization is a technique for storing computed values in-memory. Essentially, it's a fancy name for in-memory cache.

Why Memoize?

Memoization is useful when you have potentially expensive or highly repetitive computations that need to be executed. Rather than re-running the computation on each iteration, your routine computes once and fetches already computed values from memory.

'use strict';
const { createBackgroundTransaction, endTransaction } = require('newrelic');
const fs = require('fs');
createBackgroundTransaction('fileProcessing', () => {
return new Promise((resolve, reject) => fs.readFile('/tmp/input.txt', (err, file) => {
if (err) {
return reject(err);
}

Keybase proof

I hereby claim:

  • I am elliotttf on github.
  • I am elliotttf (https://keybase.io/elliotttf) on keybase.
  • I have a public key whose fingerprint is 44E1 73E2 CF8C F08C 87D6 7685 BCCE 227F C0D4 9E70

To claim this, I am signing this object:

@elliotttf
elliotttf / README.md
Last active March 3, 2016 21:48
socket stuff

To use

node master&
node test&
# wait ~7 seconds
pkill -SIGINT -x test-server
@elliotttf
elliotttf / master.js
Last active February 23, 2016 14:56
adios example
'use strict';
/**
* @file master.js
* Master process code for adios-example.
*/
const cluster = require('cluster');
const os = require('os');
const path = require('path');
# Bot factoid.
#
# facts - List all the stored definitions.
# <subject> is <definition> - Define a word or subject.
# forget <subject> - Remove a definition.
u = require 'underscore'
util = require 'util'
module.exports = (robot) ->
@elliotttf
elliotttf / theme_it_once.info
Last active August 29, 2015 13:56
Example source for "theme it once" blog post.
name = Theme it Once Example
description = Example of sharing markup with a front-end and back-end template engine in Drupal.
core = 7.x
elliotttf@4kmba:~$ php /tmp/test.php
Notice: Undefined index: baz in /private/tmp/test.php on line 15
Notice: Undefined index: baz in /private/tmp/test.php on line 16
<?php
$node = menu_get_object();
if (empty($node)) {
$node = node_load(arg(1));
}
@elliotttf
elliotttf / images.js
Created May 26, 2013 21:41
Helper function to pull data from flickr for 4k node.js training.
var request = require('superagent');
var Stream = require('stream');
/**
* Get Images function
*
*/
module.exports = function nodes (url, fn) {
var data = '';
// Set up a stream to pipe data to.