Skip to content

Instantly share code, notes, and snippets.

@ipedro
ipedro / Objective-C String Sanitation
Created November 13, 2014 15:13
Removes accents, spaces, tabs and punctionation from a given string
+(NSString*)sanitizeString:(NSString *)originalString
{
// example string
// NSString *unfilteredString = @"!@#$%^&*()_+|abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
// define the characters you want to allow
NSString *allowedChars =@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
// makes an inverted set based on your setting
NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:allowedChars] invertedSet];
@ipedro
ipedro / makeCountriesJSON.m
Last active January 8, 2016 15:38
extract country display names in different languages
-(void)makeCountriesJSON
{
NSArray<NSString*> *localeIds = @[@"pt", @"en"];
NSArray<NSString*> *countryCodesArray = [NSLocale ISOCountryCodes];
NSMutableString *json = [NSMutableString stringWithString:@"{"];
[localeIds enumerateObjectsUsingBlock:^(NSString * localeId, NSUInteger localeIndex, BOOL * _Nonnull stop) {
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:localeId];
@ipedro
ipedro / podforceupdate.sh
Created March 18, 2016 16:15 — forked from mbinna/podforceupdate.sh
Clear CocoaPods cache, re-download and re-install all pods
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
@ipedro
ipedro / gcd_thread.m
Last active March 23, 2016 18:37
GCD background thread
// get off main thread and execute costly code
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
// jump back to main thread and update your UI
dispatch_async(dispatch_get_main_queue(), ^{
});
});
@ipedro
ipedro / post-checkout-hook
Created August 13, 2021 14:59
Post-checkout hook clear DerivedData and re-open Xcode if needed
#!/bin/bash
PROCESS=Contents/MacOS/Xcode
WORKSPACE={Your Workspace/Project Path}
CACHE=~/Library/Developer/Xcode/DerivedData
# --------
previousHead=$1
currentHead=$2
@ipedro
ipedro / HxdButtonProtocol.swift
Created November 3, 2021 15:28
HxDButton interface proposal
protocol HxDButtonProtocol {
init(title: String?, image: UIImage?, configuration: HxDButtonConfigurationProtocol, actionHandler: (() -> Void)?)
init(title: String?, image: UIImage?, actionHandler: (() -> Void)?)
var image: UIImage? { get }
var imageView: UIImageView? { get }
var title: String? { get }
@ipedro
ipedro / NSObjectProtocol+SwiftUI.swift
Last active August 18, 2022 23:03
UIKit -> SwiftUI
import SwiftUI
// MARK: - UIKit.UIView -> SwiftUI.View
public extension NSObjectProtocol where Self: UIView {
/// Creates a wrapper for a UIKit view that you use to integrate that view into your
/// SwiftUI view hierarchy.
///
/// For best results set sensible values for [content compression resistance](https://developer.apple.com/documentation/uikit/uiview/1622526-setcontentcompressionresistancep),
/// and [content hugging priority](https://developer.apple.com/documentation/uikit/uiview/1622485-setcontenthuggingpriority) in your content view and it's immediate subviews.
alias: Luz Sala Jantar
description: ""
trigger:
- type: motion
platform: device
device_id: 0f52625e2f8107945c7039224cd45b8c
entity_id: ba6fd12b9550964f2645da6481182867
domain: binary_sensor
id: motion_on
for: