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;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
a.sort(() => .5 - Math.random() ).slice(0, 4); | |
//=> [3, 1, 6, 5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
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.
function groupBy(key) {
return function group(array) {
return array.reduce((acc, obj) => {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { | |
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';
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.