Skip to content

Instantly share code, notes, and snippets.

View iainbryson's full-sized avatar

Iain Bryson iainbryson

View GitHub Profile
@iainbryson
iainbryson / inflect.js
Created October 3, 2021 10:52
Javascript naming utilities like Rails' inflector
// Tools like rails' inflector
const camelizeFromArray = arr =>
arr.map((w, idx) => w.replace(/./, m => (idx === 0 ? m.toLowerCase() : m.toUpperCase()))).join('');
const constizeFromArray = arr => arr.map((w, idx) => w.replace(/./, m => m.toUpperCase())).join('');
const arrayFromKebab = (text, separator = '-') => text.split(separator);
const camelizeFromKebab = (text, separator = '-') => camelizeFromArray(text.split(separator));

Keybase proof

I hereby claim:

  • I am iainbryson on github.
  • I am iainbryson (https://keybase.io/iainbryson) on keybase.
  • I have a public key ASCnAaRxgWjS_tt84PNSoO9_2kkg-GgeQzxjx-V4FzkDOQo

To claim this, I am signing this object:

@iainbryson
iainbryson / trip-plan.rb
Last active February 27, 2016 17:12
Produce the silly social media itinerary string from airport codes. i.e.: $ bundle exec ruby trip-plan.rb yields: SEA FRA JED ADD SEA🇺🇸 → FRA🇩🇪 → JED🇸🇦 → ADD🇪🇹
require 'csv'
require 'optparse'
require 'net/http'
require 'uri'
require 'countries/global'
require 'awesome_print'
#
# Airport ID Unique OpenFlights identifier for this airport.
# Name Name of airport. May or may not contain the City name.
@iainbryson
iainbryson / geographical-center.js
Last active August 29, 2015 14:23
Compute the geographical center of a series of points specified by latitude and longitude
// compute the geographical center of a series of points/
// (1) transform all points to (unit) XYZ coordinates
// (2) average them
// (3) compute the unit vector of the average
// (4) transform the unit vector back to latitude/longitude
function geographicalCenter(points) {
"use strict";
if (points.length == 1) return points[0];
@iainbryson
iainbryson / upload_blog_imags.py
Created March 5, 2015 23:12
Enumerates a folder full of images and generates a draft markdown blog post consisting in a list of images using the IPTC title and EXIF caption metadata in each image file.
#!/usr/local/bin/python
import datetime
import time
import getopt
import os
import sys
import re
import dateutil.parser
from PIL import Image
from PIL.ExifTags import TAGS
#!/usr/bin/env python
# (c) 2012 Brett Kelly.
# Licensed under the MIT license
# http://www.opensource.org/licenses/mit-license.php
import re
import sys
try:
from urllib2 import urlopen, Request, HTTPError
@iainbryson
iainbryson / MailWebPage.ps1
Last active April 8, 2023 06:56
Use IE to send an email of a fully-rendered webpage
#requires -Version 3
param(
[string]$url = "www.example.com",
[string]$subject,
[string]$fromMail = "sending_account@example.com"
[string[]]$toMail = ("receiving_account@example.com")
[switch]$dontSend = $false
)