Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mpvosseller
mpvosseller / gist:6969154
Last active December 25, 2015 11:29
Category on an NSArray to return n random elements.
@interface NSArray (MPV)
- (NSArray*) mpv_randomElements:(NSUInteger)maxElements;
@end
@implementation NSArray (MPV)
- (NSArray*) mpv_randomElements:(NSUInteger)maxElements {
NSUInteger numElementsToPick = MIN(self.count, maxElements);
@mpvosseller
mpvosseller / gist:c0d15fa497a1256977dc
Last active August 29, 2015 14:04
Updated shell script to install Charles's SSL CA certificate to the keychain for iOS 8 simulators. The change is to support the new path used in iOS 8 simulators. The original shell script is stored here: http://www.charlesproxy.com/documentation/faqs/ssl-connections-from-within-iphone-applications
#/bin/bash
install() {
if [ -f "$SQLITEDBPATH" ]; then
cp -n "$SQLITEDBPATH" "$SQLITEDBPATH.charlesbackup"
sqlite3 "$SQLITEDBPATH" <<EOF
INSERT INTO "tsettings" VALUES(X'189B6E28D1635F3A8325E1E002180DBA2C02C241',X'3123302106035504030C1A436861726C65732050726F78792053534C2050726F7879696E6731243022060355040B0C1B687474703A2F2F636861726C657370726F78792E636F6D2F73736C3111300F060355040A0C08584B3732204C74643111300F06035504070C084175636B6C616E643111300F06035504080C084175636B6C616E64310B3009060355040613024E5A',X'3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223F3E0A3C21444F435459504520706C697374205055424C494320222D2F2F4170706C652F2F44544420504C49535420312E302F2F454E222022687474703A2F2F7777772E6170706C652E636F6D2F445444732F50726F70657274794C6973742D312E302E647464223E0A3C706C6973742076657273696F6E3D22312E30223E0A3C61727261792F3E0A3C2F706C6973743E0A',X'3082045E30820346A003020102020101300D06092A864886F70D01010505003081913123302106035504030C1A436861726C65732050726F78792053534C2050726F7879696E67312430
@mpvosseller
mpvosseller / gist:4adac1e421d5c5e44f8e
Created September 26, 2014 21:02
Block based replacement for -[NSObject performSelector:withObject:afterDelay:]
// Block based replacement for
// -[NSObject performSelector:withObject:afterDelay:]
// because I can never remember how to do it with the dispatch_after & dispatch_time functions
//
// NSObject+MPV.h
// iFoodler
//
// Created by Michael Vosseller on 9/26/14.
@mpvosseller
mpvosseller / gist:8897b379f040e0ca1476
Created January 20, 2016 04:25
Xcode Build Phase Run Script to Disable AppTransportSecurity in DEBUG Simulator Builds
#!/bin/sh
## Disable AppTransportSecurity in DEBUG Simulator Builds
if [[ ${CONFIGURATION} == "Debug" ]] && [[ $PLATFORM_NAME == *"simulator"* ]]; then
TARGET_INFOPLIST="${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}"
## Delete NSAppTransportSecurity entry if it already exists
/usr/libexec/PlistBuddy -c "Delete :NSAppTransportSecurity" "${TARGET_INFOPLIST}" 2>/dev/null
@mpvosseller
mpvosseller / make-ios-icons
Created February 12, 2018 18:31
Given a 1024x1024 iOS app icon this script creates all the other requires sizes
#!/bin/sh
convert Icon-1024.png -resize 20x20 Icon-20.png
convert Icon-1024.png -resize 40x40 Icon-20@2x.png
convert Icon-1024.png -resize 60x60 Icon-20@3x.png
convert Icon-1024.png -resize 29x29 Icon-29.png
convert Icon-1024.png -resize 58x58 Icon-29@2x.png
convert Icon-1024.png -resize 87x87 Icon-29@3x.png
convert Icon-1024.png -resize 40x40 Icon-40.png
convert Icon-1024.png -resize 80x80 Icon-40@2x.png
convert Icon-1024.png -resize 76x76 Icon-76.png
@mpvosseller
mpvosseller / example.swift
Last active February 28, 2018 19:53
When implementing a protocol property that returns an optional value you must explicitly declare the type (as an optional) in your implementation. See below comment for details.
protocol MyProtocol {
var name: String? { get }
}
extension MyProtocol {
var name: String? {
return "aDefaultName"
}
}
@mpvosseller
mpvosseller / gist:5749ad19d046cf14ebf24c837665dc25
Created May 28, 2018 14:59
Use Slack reminders to improve timely attendance
/remind #general "Team meeting starts in 15 minutes https://meet.google.com/XXXXXXX" at 10:45AM every Monday
/remind #general "Team meeting starts in 5 minutes https://meet.google.com/XXXXXXX" at 10:55AM every Monday
/remind #general "Team meeting starts in 1 minute https://meet.google.com/XXXXXXX" at 10:59AM every Monday
@mpvosseller
mpvosseller / focus.sh
Last active September 25, 2020 15:22
shell aliases to temporarily block and unblock a set of hostnames to better focus
# add to your shell startup file (e.g. ~/.zshrc or ~/.bash_profile)
export FOCUS_IGNORE_SITES="twitter.com api.twitter.com www.facebook.com www.nytimes.com"
alias focus='sudo echo "127.0.0.1 ${FOCUS_IGNORE_SITES} # FOCUS_IGNORE_SITES" | sudo tee -a /etc/hosts > /dev/null'
alias unfocus="sudo sed -i '' '/FOCUS_IGNORE_SITES/d' /etc/hosts"
@mpvosseller
mpvosseller / UnknownMaybe.ts
Created May 3, 2021 02:10
UnknownMaybe: utility type that treats an object as "unknown but might be of type T"
// utility type that treats an object as "unknown but might be of type T"
// allows you to access each property that T has but assumes the value is `unknown | undefined`
// this lets you test the values of each property to determine if it is in fact a T
// autocomplete and refactoring the property names work
// you get a compiler error if you try to access a property not in T
type UnknownMaybe<T> = {
[P in keyof T]?: T[P] extends object ? UnknownMaybe<T[P]> : unknown
}
interface Message {
@mpvosseller
mpvosseller / txt-preview.zsh
Created November 26, 2021 13:27
txt-preview - function to open text from stardard-input in Preview
## function to open text from stardard-input in Preview
## inspired by the `man-preview` function of Oh My Zsh that opens any man page in Preview https://github.com/ohmyzsh/ohmyzsh/blob/b60b3f184275c39800dd7284d6904fcf295b3956/plugins/macos/macos.plugin.zsh#L221
## requires enscript: `brew install enscript`
## example usage:
## echo "hello world" | txt-preview
function txt-preview() {
enscript -q -B -p- | open -f -a Preview
}