Skip to content

Instantly share code, notes, and snippets.

View ahcode0919's full-sized avatar
🏠
Working from home

A. Hinton ahcode0919

🏠
Working from home
  • Worldwide
View GitHub Profile
@ahcode0919
ahcode0919 / swift-measurement.swift
Last active April 17, 2017 22:51
Example of Measurements and Units in Swift 3.0
extension String {
func getDecimalDigits(includeDecimal: Bool = true) -> String {
let set = includeDecimal ? "1234567890.": "1234567890"
return self.components(separatedBy: CharacterSet(charactersIn: set).inverted).joined()
}
func lettersOnly() -> String {
let characterSet = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").inverted
@ahcode0919
ahcode0919 / DeviceCheck.swift
Created April 19, 2017 18:54
Check if Application is running on a simulator or physical iOS device
struct Device {
/// Detects if the current architecture is a Simulator
static let isSimulator: Bool = {
var isSim = false
#if arch(i386) || arch(x86_64)
isSim = true
#endif
return isSim
}()
@ahcode0919
ahcode0919 / Swift-Comments.swift
Created April 28, 2017 11:33
Comment formatting in Swift
import Foundation
/// General doc comment
struct SomeClass {
private static var count: Int = 0
let aString: String
// MARK: - Initializers
init(aString: String) {
@ahcode0919
ahcode0919 / dateHelpers.groovy
Last active May 4, 2017 16:31
Collection of Date/Time helpers
static boolean isBetween(String start, String end) {
def sdf = new SimpleDateFormat("HH:mm")
def startCalendar = Calendar.getInstance()
startCalendar.setTime(sdf.parse(start))
def endCalendar = Calendar.getInstance()
endCalendar.setTime(sdf.parse(end))
def currentCalendar = Calendar.getInstance()
@ahcode0919
ahcode0919 / Swift-Codable.swift
Created June 6, 2017 22:53
Swift 4 Codable example (Type -> JSON)
//Simple Type - Person
struct Person: Codable {
let name: String
let age: Int
func getString() -> String {
return "Name: \(name), Age: \(age)"
}
}
@ahcode0919
ahcode0919 / swift-custom-encode-decode.swift
Last active July 16, 2022 22:25
Custom JSON encoding / decoding in Swift 4
import UIKit
//Abbreviated OpenAPI product response for example purposes
let jsonData = """
{
"paging": {
"total": 8,
"offset": 0,
"limit": 40,
"returned": 8
@ahcode0919
ahcode0919 / simulator.sh
Last active June 14, 2017 17:25
Get current iOS Simulator version from command line
read SIMVERSION <<< $(xcrun simctl list | awk '/^iOS[[:space:]][0-9\.]+/ { print $2 }')
#echo $SIMVERSION
#Output: 10.3
@ahcode0919
ahcode0919 / findFileAndPerformCommand.sh
Created March 2, 2018 23:24
Find file and perform command script
find "{directory}" -name "{filename}" -print0 | xargs -0 "{command}"
# Example find "./" -name "*.txt" -print0 | xargs -0 echo
@ahcode0919
ahcode0919 / git-author-rewrite.sh
Last active May 7, 2018 01:41 — forked from octocat/git-author-rewrite.sh
Simple script for updating the commit author in a repository across all branches
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="OLD EMAIL ADDRESS"
CORRECT_NAME="NEW NAME"
CORRECT_EMAIL="NEW EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@ahcode0919
ahcode0919 / compile-files.py
Created June 21, 2018 23:17
Check all python file in current directory tree for compilation
import compileall
import os
import sys
# Get path of this file's directory
directory = os.path.dirname(os.path.realpath(__file__))
# Check that files are compileable
success = compileall.compile_dir(dir=directory, maxlevels=20, force=True)