Skip to content

Instantly share code, notes, and snippets.

Michael Brown mluisbrown

Block or report user

Report or block mluisbrown

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mluisbrown
mluisbrown / FixBTSound.applescript
Last active Jul 7, 2019
AppleScript to set macOS audio input device to "Internal Microphone"
View FixBTSound.applescript
-- Sets your audio input source to "Internal Microphone"
-- Frequently needed if you use bluetooth headpohones and
-- run the Xcode iOS simulator, which will often set your
-- headphones to be the input device, resulting in a drastic
-- decrease in sound quality, and making it mono
tell application "System Preferences" to activate
tell application "System Preferences"
reveal anchor "input" of pane id "com.apple.preference.sound"
end tell
@mluisbrown
mluisbrown / index.ts
Last active Oct 11, 2017
Simple JSON validation example using RamdaJS and fp-ts with Typescript
View index.ts
import { both, converge, equals as eq, ifElse, not, pipe, toLower, type, keys, curry } from "ramda"
import { Either, left, right, isLeft, isRight, getOrElse } from "fp-ts/lib/Either"
export type Json = string|number|boolean|Date|JsonObject
interface JsonObject {
[x: string]: Json;
}
interface JsonArray extends Array<Json> { }
@mluisbrown
mluisbrown / Array2Dict.swift
Last active Dec 14, 2016
Generic Swift function to convert an Array into a Dictionary using a key from each object in the Array
View Array2Dict.swift
func dict<T, U: Hashable>(from array: [T], getKey: (T) -> U) -> [U : T] {
var dict: [U : T] = .init(minimumCapacity: array.count)
array.forEach {
dict[getKey($0)] = $0
}
return dict
}
@mluisbrown
mluisbrown / main.swift
Last active Jul 19, 2016
UTF16 encode and decode
View main.swift
import Foundation
func encodeString(str: String) -> String {
return Array(str.utf16).map {
String(format: "%04x", $0)
}.reduce("") {
return $0 + $1
}
}
@mluisbrown
mluisbrown / main.swift
Created Jul 10, 2016
Swift code to find and count all Circular Primes below 1 million (Project Euler problem 35)
View main.swift
// Circular primes
// Problem 35
// The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
//
// There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
//
// How many circular primes are there below one million?
import Foundation
@mluisbrown
mluisbrown / AppDelegate.h
Last active Jul 3, 2019
PersistentStack for using Core Data with iCloud sync in iOS 7, adapted from code by Chris Eidhof for objc.io #4 (http://www.objc.io/issue-4/full-core-data-application.html). The most important thing is that you don't have to know whether the user is using iCloud or not, or even has an iCloud account on their device. Core Data now transparently h…
View AppDelegate.h
@import UIKit;
#import "PersistentStack.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
You can’t perform that action at this time.