Skip to content

Instantly share code, notes, and snippets.

View cumanzor's full-sized avatar

Carlos Umanzor cumanzor

  • TicketSauce.com, Inc.
  • Costa rica
View GitHub Profile
@cumanzor
cumanzor / steppedSlider.swift
Created June 6, 2016 03:01
stepped UISlider.
let step: Float = 50;
// extra slider initialization. the IBAction func below points to the UISlider we are using.
@IBAction func onStrengthChange(sender: UISlider) {
let roundedValue = round(sender.value/step) * step
sender.value = roundedValue
}
@cumanzor
cumanzor / MakeMediumReadadableUserscript.user.js
Last active March 22, 2020 19:21 — forked from luke3butler/MakeMediumReadadableUserscript.user.js
Userscript version of the MMRA (Make Medium Readable Again) Chrome extension
// ==UserScript==
// @name Make Medium Readable Userscript
// @namespace http://make.medium.readable.again
// @version 0.1
// @description https://github.com/thebaer/MMRA
// @author luke3butler (Credits to Matt Baer)
// @match *://*/*
// @grant none
// ==/UserScript==
@cumanzor
cumanzor / getfontfamily.txt
Last active June 13, 2019 20:45
get ios font family valid names #ios #lldb #debug
In the lldb cli:
po [UIFont fontNamesForFamilyName:@"Avenir"]
<__NSArrayM 0x608000247ec0>(
Avenir-Oblique,
Avenir-HeavyOblique,
Avenir-Heavy,
Avenir-BlackOblique,
Avenir-BookOblique,
@cumanzor
cumanzor / alert.swift
Created December 5, 2018 07:11
[Show simple UIAlerts from any VC] #ios #swift
extension UIViewController {
func showAlert(withTitle title: String, message : String, withActions actions:[UIAlertAction] = [], withCompletion c:(()->())?=nil) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
if actions.isEmpty{ // default ok action
let defaultAction = UIAlertAction(title: "Ok", style: .default)
alertController.addAction(defaultAction)
}
for action in actions{
@cumanzor
cumanzor / logAllocation.swift
Created November 16, 2018 06:35
[Manually chasing memory leaks] #swift
// can be made dry by adding a alloc/dealloc parameter
// add the DEBUGALLOC flag to Active Compilation Conditions -> Debug and use it only when necessary.
// note that you should be using Instruments for this, but this helps to catch issues in real time when running the app, and I gnenerally don't recommend following this approach for several reasons.
func LogDealloc<T>(from caller:T, filename: String = #file, line: Int = #line, funcname: String = #function){
#if DEBUGALLOC
let file = ("\(filename)" as NSString).lastPathComponent as String
let objName = String(describing: type(of: caller))
@cumanzor
cumanzor / UITableViewTransparentBg.swift
Last active September 28, 2018 22:59
UITableView transparent background #ios #swift #uikit
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath)
cell.backgroundColor = .clear
cell.backgroundView = UIView()
cell.selectedBackgroundView = UIView()
return cell
}
@cumanzor
cumanzor / customError.swift
Created December 16, 2017 21:34
localizable error types
// avoid the whole switch error type set description pattern we were using before (unless custom actions need to be attached or something)
// see: https://stackoverflow.com/questions/39176196/how-to-provide-a-localized-description-with-an-error-type-in-swift
import Foundation
public enum customError:Error{
case NONETWORK
case INVALIDJSON
case UNEXPECTEDRESPONSE
case INVALIDCREDENTIALS
/**
* Attempts to parse the string into a SK address.
* https://en.wikipedia.org/wiki/Addresses_in_South_Korea#Postal_Address
* https://en.wikipedia.org/wiki/ISO_3166-2:KR
* https://en.wikipedia.org/wiki/Administrative_divisions_of_South_Korea#Gun_.28County.29
* @returns An object of the form {province, city, street, zip}
*/
function parseAddress(string) {
var address = {};
address.extra = [];