Skip to content

Instantly share code, notes, and snippets.

View ericelliott's full-sized avatar
💭
https://leanpub.com/composingsoftware

Eric Elliott ericelliott

💭
https://leanpub.com/composingsoftware
View GitHub Profile
@ericelliott
ericelliott / essential-javascript-links.md
Last active April 22, 2024 10:15
Essential JavaScript Links
@ericelliott
ericelliott / env-examples.md
Last active February 6, 2024 20:57
env-examples

Most configuration really isn't about the app -- it's about where the app runs, what keys it needs to communicate with third party API's, the db password and username, etc... They're just deployment details -- and there are lots of tools to help manage environment variables -- not the least handy being a simple .env file with all your settings. Simply source the appropriate env before you launch the app in the given env (you could make it part of a launch script, for instance).

env files look like this:

SOMEVAR="somevalue"
ANOTHERVAR="anothervalue"

To source it:

$ source dev.env # or staging.env, or production.env, depending on where you're deploying to

const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const fn1 = s => s.toLowerCase();
const fn2 = s => s.split('').reverse().join('');
const fn3 = s => s + '!'
const newFunc = pipe(fn1, fn2, fn3);
const result = newFunc('Time'); // emit!
@ericelliott
ericelliott / manifest.json
Created November 8, 2016 00:35
Sample manifest.json
{
"name": "My Progressive Web Application",
"short_name": "Progressive",
"start_url": "/?home=true",
"icons": [
{
"src": "/icons/icon36.png",
"sizes": "36x36",
"type": "image/png"
},
@ericelliott
ericelliott / .gitignore
Created November 15, 2016 19:51
Sample Node project .gitignore
node_modules
build
npm-debug.log
.env
.DS_Store
@ericelliott
ericelliott / class-constructor-factory-examples.js
Last active August 28, 2023 18:18
Class, Constructor, Factory
// class
class ClassCar {
drive () {
console.log('Vroom!');
}
}
const car1 = new ClassCar();
car1.drive();
@ericelliott
ericelliott / cuid.js
Created August 31, 2012 21:31
CUID - A Better Browser-side UID (Intentionally not GUID compliant)
/**
* cuid.js
* Collision-resistant UID generator for browsers and node.
* Sequential for fast db lookups and recency sorting.
* Safe for element IDs and server-side lookups.
*
* Extracted from CLCTR
*
* Copyright (c) Eric Elliott 2012
* MIT License
@ericelliott
ericelliott / js-concepts.md
Created November 14, 2014 20:43
Seven JS Concepts You Must Understand Before Your Next Job Interview

Here are seven JavaScript concepts you must understand before you go into your next JavaScript job interview:

  1. Prototypes - JavaScript is a prototype-based language. Even more, it's a delegation-based system, which means that each object has a prototype chain. When you try to access a property on an object, and that property is not found, JavaScript looks at the object's prototype. The prototype is a delegate object, which means that the property lookup is delegated to the prototype object. That object, in turn, may have its own prototype. The search continues up the prototype chain until it reaches the root prototype, which is usually Object.prototype. The best feature of this system is that many object instances can share the same methods on a prototype object, which conserves memory and enables easy code reuse. To assign a prototype to a new object, you can use Object.create(prototypeObject). Prototypal OO is the first course being offered in the "Learn JavaScript" series.

  2. Functional Programming

/*
A neuron is basically the sum of its synapses.
Along with a trigger threshold, that's all we need to calculate
whether or not it will trigger at any given moment:
*/
const neuron = ({ synapses = [], threshold = 1 } = {}) => ({
synapses,
threshold
});
@ericelliott
ericelliott / defaults-overrides.md
Last active May 7, 2023 13:52
ES6 defaults / overrides pattern

ES6 Defaults / Overrides Pattern

Combine default parameters and destructuring for a compact version of the defaults / overrides pattern.

function foo ({
    bar = 'no',
    baz = 'works!'
  } = {}) {