Skip to content

Instantly share code, notes, and snippets.

View huttj's full-sized avatar

Joshua Hutt huttj

  • Seattle, WA
View GitHub Profile
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
const lines = [];
@huttj
huttj / LinkedList.js
Created August 11, 2019 20:07
Just playing around with iterators
class LinkedList {
constructor(value) {
this.value = value;
this.next = null;
}
push(value) {
let end = this;
while (end.next) {
end = end.next;
@huttj
huttj / staticSiteScraper.js
Last active July 28, 2019 16:21
Scrape a site and capture all of the content (and images)
const puppeteer = require('puppeteer'); // v 1.1.0
const { URL } = require('url');
const fse = require('fs-extra'); // v 5.0.0
const path = require('path');
const NO_RESPONSE_ERROR_MESSAGE = 'No data found for resource with given identifier';
const NAME_TOO_LONG_ERROR_MESSAGE = 'ENAMETOOLONG';
const THIRTY_SECONDS_MS = 1000 * 30;
const visited = new Set();
@huttj
huttj / slackLogger.js
Created January 15, 2019 03:13
A simple logger to dump applications logs into a dedicated Slack instance. It’s the poor person’s logging system, but it works!
const https = require('https');
function postToSlack(body) {
return new Promise(function(ok, fail) {
var jsonObject = JSON.stringify(body);
// the post options
var optionspost = {
host: 'hooks.slack.com',
port: 443,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
This file has been truncated, but you can view the full file.
[{"geoid":1,"type":"state","name":"Alabama","long":-86.8283671,"lat":32.7898261,"box":[-88.473227,30.223334,-84.88908,35.008028]},{"geoid":4,"type":"state","name":"Arizona","long":-111.6644073,"lat":34.2931046,"box":[-114.81651,31.332177,-109.045223,37.00426]},{"geoid":5,"type":"state","name":"Arkansas","long":-92.4392611,"lat":34.899739,"box":[-94.617919,33.004106,-89.644395,36.4996]},{"geoid":6,"type":"state","name":"California","long":-119.6106862,"lat":37.2460656,"box":[-124.409591,32.534156,-114.131211,42.009518]},{"geoid":"","type":"state","name":"Colorado","long":-105.5478146,"lat":38.9985455,"box":[-109.060253,36.992426,-102.041524,41.003444]},{"geoid":8,"type":"state","name":"Connecticut","long":-72.725705,"lat":41.6202779,"box":[-73.727775,40.980144,-71.786994,42.050587]},{"geoid":9,"type":"state","name":"Delaware","long":-75.5004023,"lat":38.9870086,"box":[-75.788658,38.451013,-75.048939,39.839007]},{"geoid":10,"type":"state","name":"Georgia","long":-83.446338,"lat":32.6492228,"box":[-85.605165,30.
This file has been truncated, but you can view the full file.
[
{
"geoid": 1,
"type": "state",
"name": "Alabama",
"box": [
-88.473227,
30.223334,
-84.88908,
35.008028
@huttj
huttj / index.js
Created May 25, 2018 02:48
GraphQL live example
const express = require('express');
const graphqlHTTP = require('express-graphql');
const { makeExecutableSchema } = require('graphql-tools');
const events = [{
id: 1,
name: 'APIs and IPAs',
description: 'Cool event',
startTime: 'evening',
endTime: 'late evening'
@huttj
huttj / HammerspoonKarabinerKeyboardSwapper.lua
Created August 15, 2017 21:43
I use Karabiner to swap the `Command` and `Option` keys when I have an external keyboard plugged in. It's so annoying to have to manually switch the profile, though, so this script does it for me automatically, whenever I add or remove the keyboard (or when the device wakes, in case it was added or removed while it was asleep).
function switchProfile(profile)
local karabiner = "'/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli' --select-profile "
print('Switching profile to "' .. profile .. '"')
hs.execute(karabiner .. "'" .. profile .. "'");
end
function isKeyboard(device)
return string.find(device["productName"], 'Keyboard') ~= nil
end
$('[data-counter]').each(function(i, n) {
runCounter($(n));
});
function runCounter($el) {
var target = +$el.data('counter');
var step = +($el.data('step') || Math.floor(target / 711) + 2);
var commas = ''+$el.data('commas') === 'false' ? false : true;
var value = 0;