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 / 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 / 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 / .gitignore
Last active December 7, 2019 18:25
Playing around with random keys, collisions, and slow lookups
node_modules/
@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
@lukekarrys
lukekarrys / bookmarklet.js
Created October 5, 2017 19:27
Get percentage of each day of the week with commits from graph.
javascript:(()=>{const e=["Sun","Mon","Tues","Wed","Thur","Fri","Sat"],r=[...document.querySelectorAll(".js-calendar-graph-svg > g > g")].reduce((e,r)=>[...r.querySelectorAll("rect.day")].reduce((e,r,t)=>(e[t][0]+="0"===r.getAttribute("data-count")?0:1,e[t][1]+=1,e),e),e.map(()=>[0,0])).reduce((r,t,c)=>(r[e[c]]=+(t[0]/t[1]*100).toFixed(3),r),{});console.log(r)})();
@lukekarrys
lukekarrys / bookmarklet.js
Last active September 19, 2017 18:14
Totals and Winning Percentages for NFL easyofficepools.com
javascript:(()=>{[...document.querySelectorAll(".n33table tr")].forEach(t=>{const e=t.querySelector("td:first-child span span"),[n,...r]=t.textContent.trim().split(" "),l=r.slice(5).map(t=>t.match(/\d+-\d+-\d+/)).filter(Boolean).map(t=>t[0]);if(l.length>6)return;const o=l.map(t=>t.split("-").map(Number)).reduce((t,[e,n,r])=>(t[0]+=e,t[1]+=n,t[2]+=r,t),[0,0,0]);e.textContent+=` / ${o[0]}-${o[1]}-${o[2]} / ${(o[0]/(o[0]+o[1])).toFixed(3)}`});})()