Skip to content

Instantly share code, notes, and snippets.

@jalakoo
jalakoo / String+Localization.swift
Last active August 31, 2018 16:59
Simple localization category for Swift strings
import Foundation
extension String {
// Example usage: "My Text".localized()
func localized() -> String {
return Bundle.main.localizedString(forKey: self,
value: nil,
table: nil)
}
@jalakoo
jalakoo / UIView+Fades.swift
Created July 6, 2018 16:32
Swift UIView simple fading extensions
extension UIView {
func reveal() {
if self.alpha == 1.0 {
return
}
UIView.animate(withDuration: 0.5) {
self.alpha = 1.0
self.isUserInteractionEnabled = true
}
}
@jalakoo
jalakoo / QRManager.swift
Last active July 6, 2018 16:32
Manager Class for handling QR Scanning
// Requirements: info.plist: 'Privacy - Camera Usage Description'
import UIKit
import AVFoundation
import QRCodeReader //pod 'QRCodeReader.swift', '~> 8.2.0'
typealias QRManagerErrorBlock = (_ error: Error)->()
typealias QRManagerResultBlock = (_ valueScanned: String)->()
enum QRManagerError : Error {
@jalakoo
jalakoo / Git Aliases
Created June 2, 2018 05:44
Adding Git aliases globally
git config --global alias.st status
git config --global alias.br branch
git config --global alias.lo 'log --oneline --decorate=full'
@jalakoo
jalakoo / Xcode warnings run script
Last active March 7, 2018 07:04
Run script that will mark TODO/FIXME/WARNINGs as compiler warnings.
// Add this to a new run script in a target:Build Phases tab
TAGS="TODO:|FIXME:|WARNING:"
echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
@jalakoo
jalakoo / gist:1dc6d979bf2230021c4be983804ff6ee
Created January 3, 2018 17:34
Add Git branch to CL prompt
# Add this to the bottom of existing or new `~/.bash_profile`
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
@jalakoo
jalakoo / ios_symbolication_instructions.md
Last active January 3, 2018 17:35
iOS Symbolication Instructions

iOS CRASH SYMBOLICATION INSTRUCTIONS

Not ideal, but works.

  1. Copy .app, .dSYM and .crash file into a temp folder
  2. Copy the relevant crash symbols into a txt file name 'symbols.txt'. Format should look like:
0x00110176 0xb8000
0x0011003a 0xb8000
0x001d2d44 0xb8000
------------------------------
Font Family Name = [Copperplate]
Font Names = [["Copperplate-Light", "Copperplate", "Copperplate-Bold"]]
------------------------------
Font Family Name = [Heiti SC]
Font Names = [[]]
------------------------------
Font Family Name = [Kohinoor Telugu]
Font Names = [["KohinoorTelugu-Regular", "KohinoorTelugu-Medium", "KohinoorTelugu-Light"]]
------------------------------
@jalakoo
jalakoo / Swift Rest POST
Created April 25, 2016 03:57
Simple REST POST
class func postJSON(urlString:String, params:[String: AnyObject], completion:(responseDataAsString:String?, response:NSHTTPURLResponse?, error:NSError?)->()) {
let url = NSURL(string: urlString)!
let session = NSURLSession.sharedSession()
// Create request
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
@jalakoo
jalakoo / Swift REST Get JSON
Created April 25, 2016 03:56
Simple JSON REST Get
// Attempts to return requested data as Json in closure
class func getJSON(urlString:String, completion:(json:AnyObject?, response:NSHTTPURLResponse?, error:NSError?)->()){
let session = NSURLSession.sharedSession()
let url = NSURL(string: urlString)!
// Make the POST call and handle it in a completion handler
session.dataTaskWithURL(url, completionHandler: { ( data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
// Session error