Skip to content

Instantly share code, notes, and snippets.

Shaun Scovil sscovil

Block or report user

Report or block sscovil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View simple-cache-example.php
<?php
class API {
public static function fetchUser($userID) {
static $cache = [];
$url = "https://example.com/users";
$method = "GET";
if (isset($cache[$url][$method][$userID])) {
@sscovil
sscovil / public.asc
Last active May 7, 2018
PGP Public Key
View public.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: GPGTools - https://gpgtools.org
mQINBFrwuf0BEADF1LS3UCcPN4Jw0a/UWpKtqN31unqpoTGZ17hst/4Qqo7N/zeE
txpT/LBv13o2uQNEPen9s9HgwvnZI4JMh90Yvr53uSedI0qHKdHWF6JvG90JW702
HySmDN2sZdXofB+Knk3OszQdgYpNBMTkulw+q3qAnUhkvyHe3mp/iFj3LO+U6ILV
CYlZ1Ds7HnVfKrLm0kBdaiVvKXySQ0O+J/vQZejdXLNa55CXWANUF1KhngcZO814
cFtKgEJqzHCS+0NqetqLZ/NXLPiCuEDoK7cKAFqxj2kcXAsPF3JrXuMZqXNph7Bd
Y6mO70kv76XqUbZdPwTtSgRWS6LJPELNe4M9FCKZYbKwwRX8mH4EncLwgGmFEjaO
mZwwAcumHx8/tJV4sdopCEKqjI6VUL0teM92tKyZPXUafrJDpGd3uQxICeAp5xmG
@sscovil
sscovil / until.js
Created Feb 20, 2018
A simple utility for Node.js to wait until a predicate function returns truthy before moving on; for use with ES6 async/await syntax.
View until.js
/**
* Utility that waits for @predicate function to return truthy, testing at @interval until @timeout is reached.
*
* Example: await until(() => spy.called);
*
* @param {Function} predicate
* @param {Number} interval
* @param {Number} timeout
*
* @return {Promise}
@sscovil
sscovil / base.js
Last active Jan 2, 2018
Objection.js base model with code coverage
View base.js
'use strict';
const Knex = require('knex');
const { knexSnakeCaseMappers, Model } = require('objection');
const uuid = require('uuid');
const knex = Knex({
client: 'pg',
connection: {
@sscovil
sscovil / custom.css
Last active May 24, 2017
CSS Exercise: What will the output look like, based on the CSS? By only editing custom.css, change the color of "Item 1" to purple.
View custom.css
/* Add custom CSS rules here */
@sscovil
sscovil / en.json
Last active May 16, 2017
Node Express server with i18next. Language files go in a `locales/` directory.
View en.json
{
"home": {
"title": "Hello World!"
}
}
@sscovil
sscovil / mixin.js
Created Oct 5, 2016
Shallow (non-recursive) object key-to-camelCase mapper Lodash mixin
View mixin.js
const _ = require('lodash');
function camelCaseKeys(obj) {
return _.mapKeys(obj, (value, key) => {
return _.camelCase(key);
});
}
_.mixin({camelCaseKeys});
@sscovil
sscovil / index.js
Last active Sep 17, 2016
Node.js recipe for an index.js file that exports all other .js files in the same directory.
View index.js
'use strict';
const fs = require('fs');
const JS_FILE = /^((?!(index)).)*\.js$/;
const JS_FILE_EXTENSION = /\.js$/;
fs.readdirSync(__dirname)
.filter(file => JS_FILE.test(file))
.forEach(file => exports[file.replace(JS_FILE_EXTENSION, '')] = require(`./${file}`));
@sscovil
sscovil / all.js
Created May 12, 2016
Use multiple JS files as defaults for nconf: https://github.com/indexzero/nconf/issues/96
View all.js
module.exports = {
ENV: 'set by development.js',
ARG: 'set by development.js',
DEV: 'set by development.js'
};
@sscovil
sscovil / renameProperty.js
Created Mar 10, 2016
A JavaScript function for renaming an object property.
View renameProperty.js
function renameProperty(object, oldKey, newKey) {
if (object instanceof Object && object.hasOwnProperty(oldKey) && oldKey !== newKey) {
Object.defineProperty(object, newKey,
Object.getOwnPropertyDescriptor(object, oldKey));
delete object[oldKey];
}
}
You can’t perform that action at this time.