Skip to content

Instantly share code, notes, and snippets.

View foxfriends's full-sized avatar
🦄
Coding... probably

Cameron Eldridge foxfriends

🦄
Coding... probably
View GitHub Profile
@foxfriends
foxfriends / Keypath.js
Last active February 9, 2021 04:12
Creates functions that extract a key of an object
const PATH = Symbol('PATH'), DEREF = Symbol('DEREF');
class Keypath extends Function {
constructor(...path) {
super();
this[PATH] = path;
}
[DEREF](object) {
for (const key of this) {
@foxfriends
foxfriends / lens.js
Created October 26, 2020 17:29
Lenses for RxJS BehaviorSubjects
import { BehaviorSubject, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { get, set } from 'shades';
class Lens extends Observable {
#lens;
#source;
constructor(source, lens) {
if (!(source instanceof BehaviorSubject)) {
@foxfriends
foxfriends / sort.js
Last active September 11, 2020 13:25
export const Asc = Symbol('Asc');
export const Desc = Symbol('Desc');
/**
* @typedef {[string, direction, direction]} Order
* Describes a sorting step. The string is the key of the object, the first direction
* is the direction to sort values within the same type, and the second direction is
* the direction to sort values of different types. See {@see sort} for the default
* orderings.
*/
@foxfriends
foxfriends / Config.swift
Created October 16, 2019 01:31
Type safe wrapper around a .plist file
// MARK: - ConfigKey
protocol ConfigKey {
associatedtype Data
static var key: String { get }
}
// MARK: - Config
/// A type safe wrapper around Config.plist
@foxfriends
foxfriends / Storage.swift
Created October 16, 2019 01:28
Type safe wrapper around UserDefaults
import Foundation
// MARK: - Storage Key
protocol StorageKey {
associatedtype V: Codable
static var key: String { get }
}
// MARK: - Storage

Keybase proof

I hereby claim:

  • I am foxfriends on github.
  • I am cameldridge (https://keybase.io/cameldridge) on keybase.
  • I have a public key ASAJbuKTod9nbNzGaX-u7LfUD4USig1CqKbYipuLVdgWzAo

To claim this, I am signing this object:

import UIKit
enum Storyboard: String {
case main = "Main"
}
protocol ViewControllerNavigation {
static var storyboard: Storyboard { get }
static var identifier: String { get }
}
@foxfriends
foxfriends / String+Localization.swift
Created September 6, 2019 13:55
Wrapper around NSLocalizableString to make it a lot easier to use
extension String {
/// Loads the localized version of the current string
@inline(__always)
func localized(comment: String = "") -> String {
return NSLocalizedString(self, comment: "")
}
/// Loads the localized version of the current string, interpolating the provided values into the string
func localized(comment: String = "", _ args: CVarArg...) -> String {
return withVaList(args) {
@foxfriends
foxfriends / Symbol+Generate.js
Created December 3, 2018 00:11
Helper method to just generate symbols indefinitely
/// Returns an iterator that generates symbols indefinitely. Names can be supplied. When names run out, then the
/// names are just the index
///
/// # Usage
/// ```js
/// const [a, b, c, d, e] = Symbol.generate('a', 'b', 'c');
/// ```
Symbol.generate = function*(...names) {
let i = 0;
for (;;)
@foxfriends
foxfriends / UIFont+Features.swift
Last active August 22, 2018 23:17
Helpers to use UIKit font features in Swift
import UIKit
// Usage:
//
// ```
// UIFont.systemFont(ofSize: 14).usingFeatures([.tabularFigures])
// ```
//
extension UIFont {