Skip to content

Instantly share code, notes, and snippets.

🙂

Nikhil Vijayan nkhil

🙂
Block or report user

Report or block nkhil

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 fixtureGenerator.md

Fixture Maker

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

const uuid = require('uuid');

const ID = uuid();
View scraper.md

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';
View controller-test.js
// 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() {
View controller-example.js
// 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 Nov 8, 2019
Group Array of JavaScript Objects by Key or Property Value
View group-objects-by-property-name.md

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) => {
View statusCodeChecker.js
const fetch = require('node-fetch');
const cheerio = require('cheerio');
async function get() {
const data = await fetch('https://httpstatuses.com/200').then(res => res.text())
console.log('\n =========================>: get -> data', data);
const $ = cheerio.load(data);
const fullTitle = $('title').text();
console.log('\n =========================>: get -> title', fullTitle);
const title = fullTitle.split('—')[0];
View insertSort.md
function insertionSort(arr) {
  for(let i = 1; i < arr.length; i++) {
    let key = arr[i];
    let j = i - 1;
    while (j >= 0 && arr[j] > key) {
      arr[j + 1] = arr[j];
      j = j - 1;
    }
    arr[j + 1] = key;
View raspberry-pi-weather.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import glob
import time
import argparse
from inky import InkyPHAT
from PIL import Image, ImageDraw, ImageFont
from font_fredoka_one import FredokaOne
@nkhil
nkhil / random.js
Created Sep 12, 2019
Pick out a random number of items out of an array
View random.js
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
a.sort(() => .5 - Math.random() ).slice(0, 4);
//=> [3, 1, 6, 5]
View parcel1.js
class Parcel {
constructor(dimensions) {
this.dimensions = dimensions;
this.parcelSize = Parcel.returnParcelSize(dimensions);
this.price = Parcel.calculatePrice(dimensions);
}
static get prices() {
return {
You can’t perform that action at this time.