Skip to content

Instantly share code, notes, and snippets.

View trevordixon's full-sized avatar

Trevor Dixon trevordixon

  • Google
  • Zürich, Switzerland
View GitHub Profile

Keybase proof

I hereby claim:

  • I am trevordixon on github.
  • I am trevordixon (https://keybase.io/trevordixon) on keybase.
  • I have a public key ASCzdZDbIbkDh3klIM2pGAU-qx33WJaLpN0kgGvIjQVr-go

To claim this, I am signing this object:

@trevordixon
trevordixon / test.babel.js
Created May 23, 2019 08:49
Test async/await/Promise order
// https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=IYZwngdgxgBAZgV2gFwJYHsI2ACgLYgDmAlDAN4BQM2A7sKsjAAoBO6eqIApgHQtch0AGwBuXHMQDcVGFEyChvIekL4iUigF8KFRCgxYARmpLkZrdp178FYiT2QALLhBwSYAXgB8Z6tTkQCkoqJhrUmhraFLgA5ACMMRrGMQBMidJAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=script&lineWrap=true&presets=es2017&prettier=false&targets=&version=7.4.5&externalPlugins=
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "ne
@trevordixon
trevordixon / im.go
Last active November 24, 2017 11:36
Simple command line XMPP instant messaging program that opens a conversation with a single contact
// Adapted from https://github.com/mattn/go-xmpp/blob/master/_example/example.go.
package main
import (
"crypto/tls"
"flag"
"fmt"
"log"
"os"
@trevordixon
trevordixon / pbcopy
Created January 20, 2017 13:01
pbcopy from remote host in iTerm2
alias pbcopy="(printf '\033]1337;CopyToClipboard=\7'; cat -; printf '\033]1337;EndCopy\7')"
const CSS = require('css');
function scopeCSS(css, scope) {
const ast = CSS.parse(css);
for (let rule of ast.stylesheet.rules) {
if (rule.type == 'rule') {
rule.selectors = rule.selectors.map(selector => `${scope} ${selector}`);
}
}
return CSS.stringify(ast);
@trevordixon
trevordixon / lds_contacts.js
Last active January 17, 2019 23:56
This script downloads all of your lds.org contacts as a vCard file which can be imported into Google Contacts, MacOS Contacts, and many other contact managers. Sign in to lds.org, then open the developer console (http://debugbrowser.com/#chrome) and paste the following code into the console.
// First, get the unit number.
const getUnitNumber = fetch('https://www.lds.org/mobiledirectory/services/ludrs/1.1/mem/mobile/current-user-unitNo', {
credentials: 'include',
})
.then(response => response.json())
.then(response => response.message);
// Then download all contacts.
const getContacts = getUnitNumber.then(unitNumber => fetch(`https://www.lds.org/mobiledirectory/services/v2/ldstools/member-detaillist-with-callings/${unitNumber}`, {
credentials: 'include',
@trevordixon
trevordixon / lds.gs
Created July 3, 2016 06:25
Make signed-in requests to LDS.org from Google Apps Scripts
function example() {
// This cookie is good for many subsequent requests (until it expires)
var cookie = getCookie('[username]', '[password]');
var response = ldsGet(cookie, 'https://www.lds.org/mobiledirectory/services/v2/ldstools/current-user-detail');
Logger.log(response.getContentText());
}
function getCookie(username, password) {
var response = UrlFetchApp.fetch('https://signin.lds.org/login.html', {
@trevordixon
trevordixon / aes.hs
Created April 15, 2016 06:13
CS 465 code
-- AES encryption in Haskell using Simple AES (http://hackage.haskell.org/package/SimpleAES-0.4.2)
-- Example encryption and decryption:
import Codec.Crypto.SimpleAES
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Hex
key = B.pack "Thisismykey....."
@trevordixon
trevordixon / count_consecutive_duplicate_lines.py
Created February 1, 2016 17:15
Sublime command that replaces repeated lines with a single instance prefixed with a count (much like uniq -c).
import sublime, sublime_plugin
class CountConsecutiveDuplicateLinesCommand(sublime_plugin.TextCommand):
def run(self, edit):
# end and start mark the beginning and end of the current region to replace,
# working backwards.
start = end = self.view.size()
# Preserve trailing newline if last line is empty.
if self.view.line(end).empty():
@trevordixon
trevordixon / _readme.md
Last active January 13, 2016 00:03 — forked from koraysaritas/_readme.md
Installing Tmux on Dreamhost tmux dreamhost