Skip to content

Instantly share code, notes, and snippets.

@floatingatoll
floatingatoll / hsts-redirect-loop.md
Last active November 20, 2023 17:59
Firefox reports HSTS + HTTPS-to-HTTP redirects as a redirect loop

If you have ERR_TOO_MANY_REDIRECTS / "The page isn't redirecting properly" in Firefox, but your network console doesn't show any obvious loops, and your site includes HSTS / HTTP-Strict-Transport-Security headers;

Then you may have an https:// request that contains an Location: http:// response, which Firefox will occasionally refuse to upgrade to https://.

Update the redirect destination to https:// and see if that solves your problems.

@floatingatoll
floatingatoll / is-private-mode.js
Created January 8, 2019 19:37 — forked from jherax/is-private-mode.js
Detect if a browser is in Private Browsing mode
/**
* Detect if the browser is running in Private Browsing mode
*
* @export
* @returns {Promise}
*/
export default function isPrivateMode() {
return new Promise((resolve) => {
const on = () => resolve(true); // is in private mode
const off = () => resolve(false); // not private mode

DNS

Hostnames were not enough.

Originally, everything just had a hostname, and you either memorized the IP address or added it to /etc/hosts.

Managing hosts files was a problem, resulting in at least two systems to solve discoverability: NIS and DNS.

NIS was invented by Sun and assumed that every NIS client was able to store and query a map of the entire local network.

@floatingatoll
floatingatoll / .patch
Created February 14, 2017 23:33
socket timeout for feedparser
--- feedparser-5.2.1/feedparser/feedparser.py 2015-07-23 22:00:04.000000000 -0700
+++ feedparser.py.new 2017-02-14 15:31:11.000000000 -0800
@@ -2910,7 +2910,10 @@
return url
def _build_urllib2_request(url, agent, etag, modified, referrer, auth, request_headers):
+ _save_socket_timeout = socket.getdefaulttimeout()
+ socket.setdefaulttimeout(2.0)
request = urllib2.Request(url)
+ socket.setdefaulttimeout(_save_socket_timeout)
@floatingatoll
floatingatoll / -
Created August 30, 2016 18:20 — forked from anonymous/-
Index: hiera.yaml
===================================================================
--- hiera.yaml (revision 121269)
+++ hiera.yaml (working copy)
@@ -2,16 +2,16 @@
:backends:
- yaml
:yaml:
- :datadir: /etc/puppet/hiera
+ :datadir: /etc/puppet
@floatingatoll
floatingatoll / -
Created August 30, 2016 18:19 — forked from anonymous/-
Index: hiera.yaml
===================================================================
--- hiera.yaml (revision 121269)
+++ hiera.yaml (working copy)
@@ -2,16 +2,16 @@
:backends:
- yaml
:yaml:
- :datadir: /etc/puppet/hiera
+ :datadir: /etc/puppet
@floatingatoll
floatingatoll / nntp-stats.py
Created May 23, 2016 21:45 — forked from limed/nntp-stats.py
Calculates nntp stats
#!/usr/bin/env python
import nntplib
import re
import sys
usage = """./nntp-stats [nntp-group-name]"""
if len(sys.argv) < 2:
print usage
@floatingatoll
floatingatoll / nest_fan_cooler.sh
Created January 8, 2016 02:32
Turn on the Nest in fan-only mode when it's too hot in the living room.
#!/bin/bash
API_KEY='Authorization: Bearer API_KEY_RETRIEVED_USING_PIN_CODE'
API_URL='https://developer-api.nest.com'
TS_ID='curl_/devices_to_get_this_hash'
TS="devices/thermostats/${TS_ID}"
MIN_TEMP=70
THRESHOLD=2
@floatingatoll
floatingatoll / seconds_to_human_time.bash
Created December 3, 2013 01:48
Usage: result=$( seconds_to_human_time $SECONDS )
seconds_to_human_time () {
local result= sign= suffix= seconds=
# Precisely one argument.
if [[ ${#@} != 1 ]] || [[ -z $1 ]]; then
echo 'Usage: result=$( seconds_to_human_time $SECONDS )' 1>&2
exit 1
fi
# Record whether it's positive or negative, choosing the right suffix.
HTTP/1.1 500 Backend Servers Unavailable
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Service Unavailable</title>
<style type="text/css">
body, p, h1 {