Skip to content

Instantly share code, notes, and snippets.

View ashtonmeuser's full-sized avatar

Ashton Meuser ashtonmeuser

  • Dialpad
  • Vancouver, BC
View GitHub Profile
@ashtonmeuser
ashtonmeuser / PrettyScore.swift
Created November 6, 2017 21:53
Return a formatted score
//
// PrettyScore.swift
//
// Created by Ashton Meuser on 2017-07-21.
// Copyright © 2017 Ashton Meuser. All rights reserved.
//
import Foundation
extension Double {
@ashtonmeuser
ashtonmeuser / ColorIsLight.swift
Created November 6, 2017 21:55
Determines whether a color is light or dark
//
// ColorIsLight.swift
//
// Created by Ashton Meuser on 2017-04-26.
// Copyright © 2017 Ashton Meuser. All rights reserved.
//
import Foundation
import UIKit
@ashtonmeuser
ashtonmeuser / UUIDv1.swift
Created November 6, 2017 21:56
Creates a UUID version 1 string
//
// UUIDv1.swift
//
// Created by Ashton Meuser on 2017-07-04.
// Copyright © 2017 Ashton Meuser. All rights reserved.
//
import Foundation
extension UUID {
@ashtonmeuser
ashtonmeuser / DateTimePassed.swift
Last active November 7, 2017 00:53
Simple time passed formatter
//
// DateTimePassed.swift
//
// Created by Ashton Meuser on 2017-08-21.
// Copyright © 2017 Ashton Meuser. All rights reserved.
//
import Foundation
extension Date {
@ashtonmeuser
ashtonmeuser / MulticastDelegate.swift
Last active November 7, 2017 19:11
Multicast delegate with +=, -= syntax, removes nil delegates
//
// MulticastDelegate.swift
//
// Created by Ashton Meuser on 2017-11-06.
// Copyright © 2017 Ashton Meuser. All rights reserved.
//
// Delegate property: var multicastDelegate = MulticastDelegate<MyDelegateProtocol>()
// Assign a delegate: multicastDelegate += self
// Invoke delegate methods: multicastDelegate.invoke { $0.protocolMethod() }
@ashtonmeuser
ashtonmeuser / DarkColorFromNumeric.swift
Last active November 9, 2017 20:56
Generates dark UIColor from a numeric string provided a radix
//
// DarkColorFromHash.swift
//
// Created by Ashton Meuser on 2017-04-26.
// Copyright © 2017 Ashton Meuser. All rights reserved.
//
import Foundation
import UIKit
@ashtonmeuser
ashtonmeuser / CircleView.swift
Created November 8, 2017 21:05
Circular UIView, efficient when resizing
//
// CircleView.swift
//
// Created by Ashton Meuser on 2017-11-08.
// Copyright © 2017 Ashton Meuser. All rights reserved.
//
import UIKit
class CircleView: UIView {
const exponentialPrefix = (value, fixed = 0, unit = '') => {
const prefixes = ['y', 'z', 'a', 'f', 'p', 'n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
const expString = value.toExponential();
const [sig, exp] = expString.split('e').map(Number);
const engr = Math.floor(exp / 3) * 3;
const base = (sig * (10 ** (exp - engr))).toFixed(fixed);
const prefix = prefixes[(engr / 3) + 8];
if (typeof prefix === 'undefined') {
return `${sig.toFixed(fixed)}e${exp}${unit}`;
}
@ashtonmeuser
ashtonmeuser / aes256Encryption.js
Last active May 29, 2018 22:02
AES-256 encryption and decryption
const crypto = require('crypto');
const encryptionSecret = Buffer.from(process.env.ENCRYPTION_SECRET);
const encrypt = (string) => {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-cbc', encryptionSecret, iv);
let encrypted = cipher.update(string);
encrypted = Buffer.concat([encrypted, cipher.final()]);
// Lambda helper class
final class LambdaHelper {
// AWS config constants, etc.
private let lambdaInvoker: AWSLambdaInvoker!
static let sharedInstance = LambdaHelper()
private init() {
// Set up AWS config, etc.
lambdaInvoker = AWSLambdaInvoker.default()
}