Skip to content

Instantly share code, notes, and snippets.

View lukekarrys's full-sized avatar

Luke Karrys lukekarrys

View GitHub Profile

Keybase proof

I hereby claim:

  • I am lukekarrys on github.
  • I am lukekarryz (https://keybase.io/lukekarryz) on keybase.
  • I have a public key ASDHFjKV-21jX2bEkz2emB4ZXj2ZhBPPKlhHvbJsxnzYoAo

To claim this, I am signing this object:

@lukekarrys
lukekarrys / index.js
Last active May 1, 2021 03:26
node download file server
const http = require("http");
const fs = require("fs");
const serve = (res, data, headers) => {
res.writeHead(200, headers);
res.end(data);
};
const randomName = () => Math.random().toString().slice(2);
@lukekarrys
lukekarrys / get-all-repos-from-org.js
Created May 1, 2021 03:06
Get all repos from a GitHub org with instructions to then clone them
const { Octokit } = require("@octokit/core");
const fs = require("fs").promises;
const octokit = new Octokit({
auth: "GH_REPO_TOKEN",
});
const ORG = process.argv[2];
const PER_PAGE = 100;
const getAll = async () => {
@lukekarrys
lukekarrys / buy-a-refurb-mac.js
Created May 1, 2021 03:01
Script to find specific refurb macs for sale
import { JSDOM, VirtualConsole } from "jsdom";
import fetch from "node-fetch";
const appleUrl = (p) => {
return new URL(p, `https://www.apple.com`);
};
const fetchPage = async (url) => {
const res = await fetch(appleUrl(url));
const html = await res.text();
@lukekarrys
lukekarrys / README.md
Last active May 31, 2020 16:47
Node Crawler to find all domain links on a site and run a function on them

Node Crawler to find all domain links on a site and run a function on them

Linked to from http://lukecod.es/2012/11/18/random-problem-of-the-night/

What

This is a node.js crawler that will crawl an entire site (using crawl) to find all internal links in the entire site. It will then test each unique internal link for the presence of an optional string and then the query string into an object. All values with the same key from the query string will be pushed to an array for that key.

Usage

@lukekarrys
lukekarrys / .gitignore
Last active December 7, 2019 18:25
Playing around with random keys, collisions, and slow lookups
node_modules/
@lukekarrys
lukekarrys / extend-and-save.js
Created July 30, 2012 23:08
Quick Node script to merge to extend one JSON file with another and save it
/*global require console */
var _ = require('underscore'),
fs = require('fs'),
data = JSON.parse(fs.readFileSync('./data.json', 'utf-8')).data;
_.each(data, function(item) {
var newJson = item[0],
files = item[1];
@lukekarrys
lukekarrys / constants.js
Created November 7, 2019 18:54
Constants Proxy
module.exports = (keys) => new Proxy(
keys.reduce((acc, key) => ((acc[key] = key), acc), {}),
{
get: function(target, name) {
// Since this getter gets called for all keys, some values need to be ignored
if (
// If this proxy gets logged or inspected then name
// could be a symbol or the string inspect
typeof name === 'symbol' ||
name === 'inspect' ||
@lukekarrys
lukekarrys / index.js
Created August 21, 2019 00:37
Get ultrasignup points based on elapsed times
const timeToSeconds = (t) => t
.split(':')
.reverse()
.reduce((acc, value, i) => acc + value * Math.pow(60, i), 0)
const timesToPoints = (...times) => Math.round(times[0] / times[1] * 1000)
const main = (...times) => {
const parsed = times.map(timeToSeconds)
if (parsed.length === 3) {
@lukekarrys
lukekarrys / .gitignore
Last active September 7, 2018 00:31
Slack Draft
node_modules
token.json
db.json