Skip to content

Instantly share code, notes, and snippets.

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];
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;
#!/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 September 12, 2019 13:40
Pick out a random number of items out of an array
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
a.sort(() => .5 - Math.random() ).slice(0, 4);
//=> [3, 1, 6, 5]
class Parcel {
constructor(dimensions) {
this.dimensions = dimensions;
this.parcelSize = Parcel.returnParcelSize(dimensions);
this.price = Parcel.calculatePrice(dimensions);
}
static get prices() {
return {
const order = [
{
width: 8,
height: 9,
depth: 7,
},
{
width: 18,
height: 29,
depth: 37,
@nkhil
nkhil / github.js
Created November 25, 2018 00:29
How to close a repo, work on it and upload it to Github as a different repo
// GitHub: git clone someone else's repository & git push to your own repository
// Create a new repository at github.com. (this is your repository)
// Give it the same name as the other repository.
// Don't initialize it with a README, .gitignore, or license.
// Clone the other repository to your local machine. (if you haven't done so already)
// git clone https://github.com/other-account/other-repository.git
// Rename the local repository's current 'origin' to 'upstream'.
rm -rf node_modules && npm install
//ERROR:
//ReferenceError: internalBinding is not defined at fs.js:25:1
// SOLUTION:
// When you update node you need to run rm -rf node_modules && npm install
//to rebuild/reinstall your native modules against your new node version.
@nkhil
nkhil / gist:c1a87c28bf44da7ec77fb1e2a33907a2
Created November 2, 2018 20:22 — forked from paulallies/gist:0052fab554b14bbfa3ef
Remove node_modules from git repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
var elementsInsideBody = [...document.body.getElementsByTagName('*')];
// This makes an array of everything inside the body tag
//a function that loops through every single item
function findAndReplace(){
elementsInsideBody.forEach(element =>{
element.childNodes.forEach(child =>{
if(child.nodeType === 3){
replaceText(child);