Skip to content

Instantly share code, notes, and snippets.

View mmdock's full-sized avatar

Morgan Dock mmdock

  • Dattch
  • San Francisco, CA
View GitHub Profile
@mmdock
mmdock / UIView+SecureExtension.swift
Created September 16, 2021 18:36
Prevent screencapture / recordings on iOS
extension UIView {
/// secure a view to prevent it appearing in screenshots or screen recordings
func makeSecure() {
DispatchQueue.main.async {
let field = UITextField()
field.isSecureTextEntry = true
self.addSubview(field)
field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
import UIKit
public struct TextStyle: Equatable {
// MARK: - Instance Properties
public let font: UIFont?
public let color: UIColor?
public let backgroundColor: UIColor?
public let strikethrough: Bool
public let underline: Bool
@mmdock
mmdock / Refresh Pods
Last active August 25, 2020 00:55
When Cocoapods is messing up, start clean
#!/bin/bash
rm -rf Pods/
pod cache clean --all
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
pod install
@mmdock
mmdock / Jailbroken.swift
Created July 12, 2019 15:56
iOS Simple Jailbroken Test
///Discussion:
///In theory, if app is able to have visibility of a file outside the app's environment then it is jailbroken.
///For this test, we will be checking for common files found from various ways of jailbreaking an iOS device.
///As a final test: try writing outside of the app's sandbox.
func isJailbroken() -> Bool{
#if targetEnvironment(simulator)
return false
#else
let fm = FileManager.default
@mmdock
mmdock / prep.py
Last active June 18, 2019 22:16
A simple file to parse out the value strings from a given key:value separated localization file (assuming 1 per line) using a given separator character. Basically a line splitter for a given file.
#!/usr/bin/env python
import codecs
import optparse
import os
import re
"""
This small script extracts values from a simple key:value localization file.
"""
@mmdock
mmdock / xcsetup
Created April 29, 2019 20:18
simple script to setup a new environment for Xcode (with maybe an existing repo)
xcode-select --install
which -s brew
if [[ $? != 0 ]]; then
# Install Homebrew
sudo ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "installed Homebrew"
else
sudo brew update
@mmdock
mmdock / difflocal.py
Created March 21, 2019 19:11
Script to help me compare two .strings files. Use during Xcode build phase to ensure localizations contain all keys
#!/usr/bin/env python
import codecs
import optparse
import os
import re
"""
This small script compares Cocoa / iOS development Localizable.strings files.
These are usually UTF-16 and difficult to compare. In addition to that,
the order of the contents of the files varies per export, making diff very
public static String getPath(Context context, Uri uri) {
final boolean needToCheckUri = Build.VERSION.SDK_INT >= 19;
String selection = null;
String[] selectionArgs = null;
// Uri is different in versions after KITKAT (Android 4.4), we need to
// deal with different Uris.
if (needToCheckUri && DocumentsContract.isDocumentUri(context.getApplicationContext(), uri)) {
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");