Skip to content

Instantly share code, notes, and snippets.

{
1991: [
{
{
artist: 'Pearl Jam',
album: 'Ten',
year: '1991',
},
{
artist: 'Soundgarden',
const albums = [
{
artist: "Pearl Jam",
album: "Ten",
year: "1991"
},
{
artist: "Pearl Jam",
album: "Yield",
year: "1998"
const transactions = [
  {
    merchantName: 'Netflix',
    amount: 5.99,
    currency: 'GBP',
    bookingDateTime: '2020-01-01T19:33:23.473Z',
  },
  {
    merchantName: 'Petfood Co',

Example of functional piping

  const pipeAsync = (...fns) => async (value) => {
    console.log('fns', fns)
    return await fns.reduce((sum, fn) => {
      if (typeof fn !== 'function') {
        throw new TypeError('fn is not a function');
      }
 return Promise.resolve(sum).then(fn);
@nkhil
nkhil / raspberry-pi-zero-w.md
Last active February 4, 2020 22:32
Raspberry pi zero w used with an inkyphat e-ink display

Using the raspberry pi zero w with an inkyphat e-ink display

raspberry-pi-inky-phat

Hey,

My name's Nikhil. I'm a JavaScript developer who doesn't know any python - I hacked this script together till I got something I liked due to just wanting something that worked, and haven't touched this code since due to having a thing that worked. If you end up improving it, I'd really appreciate a shout.

I've written a post about it here https://nikhilvijayan.com/raspberry-pi-zero-weather-display.

Fixture Maker

Working draft of fixture creator. This is a functional implementation.

const uuid = require('uuid');

const ID = uuid();

Work in progress to scrap https://httpstatuses.com/ for snippets about status codes.

const fetch = require('node-fetch');
const cheerio = require('cheerio');

const STATUS_CODES = [200, 201, 400, 500];

const URL = 'https://httpstatuses.com';
// file: controller.spec.js
const proxyquire = require('proxyquire');
const sinon = require('sinon');
const chai = require('chai');
const { expect } = chai;
describe('calculateTotal', function(done) {
it('calculates the total and updates the database', function() {
// file: controller.js
const databaseUpdater = require('../model/databaseUpdater');
// ^ This is out model function that goes and updates the database.
function updateTotal(total) {
databaseUpdater({ body: total });
}
function calculateTotal(data) {
const total = data.reduce((accumulator, number) => accumulator + number, 0);
updateTotal(total);
@nkhil
nkhil / group-objects-by-property-name.md
Last active November 8, 2019 18:41
Group Array of JavaScript Objects by Key or Property Value

How to group an array of JavaScript objects by key or property value

I first came across this code on JamieMason's gist. Here I've tried to re-create it from scratch as I found their solution slightly hard to follow.

Implementation

function groupBy(key) {
  return function group(array) {
    return array.reduce((acc, obj) => {