Skip to content

Instantly share code, notes, and snippets.

@headquarters
headquarters / delete-cookies.js
Created January 27, 2020 13:08
Delete cookies via the console
var cookies = decodeURIComponent(document.cookie).split("; "); for (var c in cookies) { var values = cookies[c].split("="); document.cookie = encodeURIComponent(values[0]) + "=" + encodeURIComponent(values[1]) + "; max-age=-1"; }
@headquarters
headquarters / visual-diff.html
Last active January 8, 2020 17:35
Visually diffing two sites with iframes: a cheap and dirty way to manually diff two versions of the same site that might only differ by a few pixels here and there.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Compare Old and New Sites Visually</title>
<style>
body {
@headquarters
headquarters / bastion-host.sh
Created January 6, 2020 18:00
SSH Tunnel to MySQL via Bastion Host
#!/bin/bash
# The following environment variables are required for connecting to the DB via an SSH tunnel:
# DBHOST -> the MySQL DB endpoint
# BASTIONUSER -> username for connecting to the bastion host, associated with your SSH key
# BASTIONHOST -> the IP or hostname of the bastion host
#
# Overriding the SSH key path is optional:
# SSHKEYPATH -> if using a non-default SSH key, set this to override ~/.ssh/id_rsa
@headquarters
headquarters / client.js
Last active December 17, 2018 13:25
Socket hang up: server
var HttpsProxyAgent = require('https-proxy-agent');
require('isomorphic-fetch');
// Attempt to fetch the origin server, but proxied through the proxy server...works in browser, but not on the CLI
// with `node fetch.js`
fetch('http://localhost:8818', {
agent: new HttpsProxyAgent('http://username:password@localhost:9818')
}).then((res) => {
console.log('Fetch response', res);
}).catch((err) => {
const maxWeight = 50;
const piles = [
{
count: 60,
weight: 10
},
{
count: 120,
weight: 30
},
@headquarters
headquarters / match-character-sequence-regex.js
Created July 28, 2018 19:12
Match a sequence of characters anywhere in a string, so long as the order is consistent.
var CSS_COLOR_NAMES = ["AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenRod","DarkGray","DarkGrey","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","Darkorange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray","DarkSlateGrey","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","GoldenRod","Gray","Grey","Green","GreenYellow","HoneyDew","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen","LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenRodYellow","LightGray","LightGrey","LightGreen","LightPink","LightSalmon","LightSeaGreen","LightSkyBlue","LightSlateGray","LightSlateGrey","LightSteelBlue","LightYellow"
@headquarters
headquarters / js-memoization.js
Last active July 28, 2018 19:10
Memoization in JavaScript using ES6 structures
function memoize(fn) {
let state = {};
return function() {
const args = [...arguments];
if(state[args]) {
return state[args];
} else {
const value = fn.apply(this, args);
@headquarters
headquarters / crash-data.rb
Last active January 27, 2020 13:11
Collect City of Raleigh Police Department vehicle crash data.
require 'bundler/setup'
require 'date'
require 'csv'
require 'nokogiri'
require "net/http"
require "uri"
require 'work_queue'
CSV_FILENAME = "crash_data.csv"
# Crash reports are at least 3 days old
@headquarters
headquarters / glimmer-blueprint-output.txt
Created February 8, 2018 19:40
output for `ember new glimmer-components -b @glimmer/blueprint`
14:16:17 Projects $ ember new glimmer-components -b @glimmer/blueprint
installing blueprint
create .editorconfig
create .ember-cli
create .watchmanconfig
create README.md
create config/environment.js
create config/module-map.d.ts
create config/resolver-configuration.d.ts
create config/targets.js
@headquarters
headquarters / scope.js
Created January 5, 2018 17:40
Scope CSS styles
var styleTags = jQuery('style');
var styleText;
var scopeClass;
var scopedStyles;
var firstChar;
styleTags.each(function(index) {
scopeClass = makeScope();
styleText = jQuery(this).text();
firstChar = styleText.trim().substring(0, 1);