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');
<?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.
define({
// Student port should match the randomly assigned port
// for this user that the node application is listening on.
url: 'http://STUDENT.nodejs.4kclass.com:STUDENT_PORT'
});
@elliotttf
elliotttf / config.js
Created May 15, 2013 12:13
Example config file for Four Kitchens node.js training.
module.exports = {
port: 1234, // Unique port number.
pollInterval: 10000, // Frequency that content endpoints will be polled at.
drupalNodesUrl: 'http://user.training-server.com/exercises/drupal/rest/node.json' // URL to student's training instance.
};
<?php
$strs = array(
'modules/system/system.menus.css',
'modules/system/system.css',
);
$re = '/^(modules\/system\/((?!system\.menus).+)\.css)$/';
foreach ($strs as $str) {
print_r(preg_match($re, $str) ? 'Yay' : 'Boo');
print PHP_EOL;
}