Skip to content

Instantly share code, notes, and snippets.

View iambriansreed's full-sized avatar
🏠
Working from my office at home

Brian Reed iambriansreed

🏠
Working from my office at home
View GitHub Profile
@iambriansreed
iambriansreed / fileUnimportedFiles.ts
Created November 4, 2022 19:34
Find files not imported.
import { resolve } from 'path';
import { promises, readFileSync } from 'fs';
const { readdir } = promises;
const ignoreFolders = ['__generated__', '__tests__'];
const notImported: string[] = ['/webpack.config', '/globals.d'];
const fileContent: Record<string, string> = {};
@iambriansreed
iambriansreed / isEqualish.test.ts
Last active November 3, 2022 04:44
isEqualish - deep-equal but ignores array order
import isEqualish from './isEqualish';
describe('compare', () => {
it('arrays should be true when different order', () => {
const obj1 = { x: 1, y: 2 };
const obj2 = { x: 3, y: 4 };
const a = [obj1, obj2];
const b = [obj2, obj1];
@iambriansreed
iambriansreed / filesDownloader.ts
Created October 30, 2022 21:11
Files Downloader - Node,TypeScript
import fs from 'fs';
import https from 'https';
async function filesDownloader(url: (iterator: number) => string, response: (iterator: number, data: string) => void, iteratorMax: number, iteratorStart = 0) {
async function getUrlData(url: string): Promise<string> {
return new Promise((resolve, reject) => {
@iambriansreed
iambriansreed / deepSet.ts
Last active October 19, 2020 22:43
Sets the value at path of object. If a portion of path doesn't exist, it's created. An alternative to https://lodash.com/docs/#set
/**
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
* An alternative to https://lodash.com/docs/#set
*
* @param {object} obj
* @param {string} keyPath
* @param {any} value
*/
export default function deepSet(
obj: { [key: string]: any },
function datesToLocalTime(...times){
const [announcementTimeStr, tooEarlyTimeStr] = times
.map((date) => date.toLocaleString().split(', ')[1].toLowerCase().replace(/:00/g, ''));
return `At ${announcementTimeStr} Steve said that ${tooEarlyTimeStr} is too early.`;
}
console.log(datesToLocalTime(
new Date('2020-03-08T19:47:00.000Z'),
new Date('2020-03-08T04:30:00.000Z')
))
'use strict';
var promiseList = [function () {
return Promise.resolve(2);
}, promiseGenerator(), promiseGenerator(), promiseGenerator(), promiseGenerator(), promiseGenerator()];
function promiseGenerator() {
return function (val) {
return new Promise(function (resolve, reject) {
resolve(val * 2);
@iambriansreed
iambriansreed / command.js
Last active June 12, 2017 00:33
Backtick Twitter Share Modal
/* NOTE: Comments need to be in multiline format like this, instead of "// Comment" */
alert("Hello World");
@iambriansreed
iambriansreed / command.js
Last active May 29, 2017 06:48 — forked from BacktickIO/command.js
WhatFont
(function(){var d=document,s=d.createElement('scr'+'ipt'),b=d.body,l=d.location;s.setAttribute('src','https://chengyinliu.com/wf.js?o='+encodeURIComponent(l.href)+'&t='+(new Date().getTime()));b.appendChild(s)})();
@iambriansreed
iambriansreed / README.md
Last active June 10, 2017 02:54
Backtick Example Command

This is an example command for Backtick. A Backtick command consists of some executable JavaScript and a bit of metadata in JSON.

Here are the required steps to create a command:

  1. Update This readme with a brief explanation of what your command does or delete this.

  2. Create a new Gist with a command.js and command.json file, or simply fork this one.

  3. Write your JavaScript in command.js. This will be injected into and executed on the page the user is currently on when they run it.

@iambriansreed
iambriansreed / README.md
Last active June 10, 2017 03:05 — forked from JoelBesada/README.md
Backtick Example Command

This is an example command for Backtick. A Backtick command consists of some executable JavaScript and a bit of metadata in JSON.

Here are the required steps to create a command:

  1. Update This readme with a brief explanation of what your command does or delete this.

  2. Create a new Gist with a command.js and command.json file, or simply fork this one.

  3. Write your JavaScript in command.js. This will be injected into and executed on the page the user is currently on when they run it.