Skip to content

Instantly share code, notes, and snippets.

Batch Edit Multi-selection

Useful bash commands for editing the text on each line of a multi-line selection in Sublime Text. Copy selections to the clipboard, run the command, paste modified selections back in the document.

Math

Math with numbers, adds +1 to each and evaluates it with bc:

@nathancahill
nathancahill / sign.js
Created May 7, 2019 16:26
Modern Node function for signing AWS REST HTTP request parameters with Version 2 Signature
const crypto = require('crypto')
module.exports = (host, method, url, params, awsAccessKeyId, awsSecretAccessKey) => {
const timestamp = (new Date()).toISOString()
const newParams = `${params}&Timestamp=${timestamp}&AWSAccessKeyId=${awsAccessKeyId}`
const sortedParams = newParams
.split('&')
.map(a => {
const [k, v] = a.split('=')
tell application "Finder"
set this_folder to (the target of the front window) as alias
set thePath to quoted form of POSIX path of this_folder
set theCmd to "cd " & thePath & ";clear;"
end tell
tell application "iTerm"
activate
set aWindow to current window

This is a Markdown representation of a small library that I wrote called Split.js. The ~500 lines of source code is here: https://github.com/nathancahill/Split.js/blob/master/split.js. While the library was an experiment in manually optimizing for file size, this document is an experiment in readable commentary alongside the code. Feel free to leave comments/submit PRs with feedback.


The programming goals of Split.js are to deliver readable, understandable and maintainable code, while at the same time manually optimizing for tiny minified file size, browser compatibility without additional requirements, graceful fallback (IE8 is supported) and very few assumptions about the user's page layout.

Make sure all browsers handle this JS library correctly with ES5. More information here: [Strict mode - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScri

function Registry(a){return new inViewRegistry(a)}var throttle=function(a,b){var c=!1;return function(){c||(a.call(),c=!0,setTimeout(function(){c=!1},b))}},inViewport=function(a,b){void 0===b&&(b=0);var c=a.getBoundingClientRect(),d=c.top,e=c.right,f=c.bottom,g=c.left;return f>b&&e>b&&window.innerWidth-g>b&&window.innerHeight-d>b},inViewRegistry=function(b){this.current=[],this.elements=b,this.handlers={enter:[],exit:[]},this.singles={enter:[],exit:[]}};inViewRegistry.prototype.check=function(b){var c=this;return this.elements.forEach(function(a){var d=inViewport(a,b),e=c.current.indexOf(a),f=e>-1,g=d&&!f,h=!d&&f;g&&(c.current.push(a),c.emit("enter",a)),h&&(c.current.splice(e,1),c.emit("exit",a))}),this},inViewRegistry.prototype.on=function(b,c){return this.handlers[b].push(c),this},inViewRegistry.prototype.once=function(b,c){return this.singles[b].unshift(c),this},inViewRegistry.prototype.emit=function(b,c){for(var d=this;this.singles[b].length;)d.singles[b].pop()(c);for(var e=this.handlers[b].length;--e>-1;
var throttle = function (callback, limit) {
var wait = false;
return function () {
if (!wait) {
callback.call();
wait = true;
setTimeout(function () {
wait = false;
}, limit);
@nathancahill
nathancahill / translate_amazon.js
Last active May 10, 2022 10:29 — forked from ideasasylum/translate_amazon.js
Translate Amazon service names into plain English (see https://www.expeditedssl.com/aws-in-plain-english)
// ==UserScript==
// @name Translate Amazon
// @namespace http://your.homepage/
// @version 0.1
// @description Translate the Amazon service names into plain English. See https://www.expeditedssl.com/aws-in-plain-english
// @author @ideasasylum
// @match https://*.console.aws.amazon.com/console/home?*
// @grant none
// ==/UserScript==

Keybase proof

I hereby claim:

  • I am nathancahill on github.
  • I am nathancahill (https://keybase.io/nathancahill) on keybase.
  • I have a public key whose fingerprint is 0475 9D4E 109F E0DB B91C F07E 0EE1 61C2 27E3 8D25

To claim this, I am signing this object:

@nathancahill
nathancahill / env.py
Created September 14, 2014 20:24
Exclude spatial_ref_sys from Alembic
"""
Mirror of code here: http://dev.utek.pl/2013/ignoring-tables-in-alembic/
Usage:
[alembic:exclude]
tables = spatial_ref_sys
"""
def exclude_tables_from_config(config_):
@nathancahill
nathancahill / gist:4bf47635ee4484746d57
Created August 22, 2014 21:27
Distance between two points
var getDistanceFromLatLonInKm = function(lat1, lon1, lat2, lon2) {
var R = 6371,
dLat = deg2rad(lat2 - lat1),
dLon = deg2rad(lon2 - lon1),
a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(eg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2),
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)),
d = R * c;