most of these require logout/restart to take effect
# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false
# Set a shorter Delay until key repeat
(defun toggle-maximize-buffer () "Maximize buffer" | |
(interactive) | |
(if (= 1 (length (window-list))) | |
(jump-to-register '_) | |
(progn | |
(set-register '_ (list (current-window-configuration))) | |
(delete-other-windows)))) | |
;; Bind it to a key. |
# Based on http://www.jonathanleighton.com/articles/2011/awesome-active-record-bug-reports/ | |
# Run this script with `$ ruby my_script.rb` | |
require 'sqlite3' | |
require 'active_record' | |
# Use `binding.pry` anywhere in this script for easy debugging | |
require 'pry' | |
# Connect to an in-memory sqlite3 database |
# Simple No-ip.com Dynamic DNS Updater | |
# | |
# By Nathan Giesbrecht (http://nathangiesbrecht.com) | |
# | |
# 1) Install binary as described in no-ip.com's source file (assuming results in /usr/local/bin) | |
# 2) Run sudo /usr/local/bin/noip2 -C to generate configuration file | |
# 3) Copy this file noip2.service to /etc/systemd/system/ | |
# 4) Execute `sudo systemctl daemon-reload` | |
# 5) Execute `sudo systemctl enable noip2` | |
# 6) Execute `sudo systemctl start noip2` |
// Sometimes it's necessary to do a bit of clean-up | |
Array.prototype.forEach.call(document.querySelectorAll('.js-comment-delete button'), function(el, i) { | |
el.removeAttribute('data-confirm'); | |
el.click(); | |
}); |
I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText
always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.
Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch
block to extract the message in the body:
fetch("/api/foo")
.then( response => {
if (!response.ok) { throw response }
return response.json() //we only get here if there is no error
})