Skip to content

Instantly share code, notes, and snippets.

View albertodebortoli's full-sized avatar

Alberto De Bortoli albertodebortoli

View GitHub Profile
@albertodebortoli
albertodebortoli / Protocolling in Swift
Last active January 28, 2018 17:36
Playing around w/ protocols in Swift
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
import UIKit
protocol HomeViewControllerProtocol: class {
func render()
}
let s: String = "Stack Overflow"
let ss1: String = (s as NSString).substring(to: 5) // "Stack"
let index: String.Index = s.index(s.startIndex, offsetBy: 5)
var ss2: String = s.substring(to: index) // "Stack"
@albertodebortoli
albertodebortoli / debounce.swift
Last active March 4, 2018 16:00 — forked from ShamylZakariya/debounce.swift
Simple Swift Debouncer
func debounce( delay:NSTimeInterval, #queue:dispatch_queue_t, action: (()->()) ) -> ()->() {
var lastFireTime:dispatch_time_t = 0
let dispatchDelay = Int64(delay * Double(NSEC_PER_SEC))
return {
lastFireTime = dispatch_time(DISPATCH_TIME_NOW,0)
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
@albertodebortoli
albertodebortoli / futures_and_promises_brainstorming.m
Created November 30, 2015 11:59
Futures & Promises brainstorming
[self job1].continueWith(^{
return [self job2];
}).continueWith(^{
return [self job3];
})
[JEPromise executeWaterfall(^{
return [self job1].[self job2].[self job3];
}).finally(^(JEFuture *fut){
@albertodebortoli
albertodebortoli / simulator_populator_xcode7
Created November 5, 2015 00:27 — forked from cabeca/simulator_populator_xcode7
This script removes and recreates all simulators in Xcode 7.
#!/usr/bin/env ruby
require 'JSON'
device_types = JSON.parse `xcrun simctl list -j devicetypes`
runtimes = JSON.parse `xcrun simctl list -j runtimes`
devices = JSON.parse `xcrun simctl list -j devices`
devices['devices'].each do |runtime, runtime_devices|
runtime_devices.each do |device|
### Keybase proof
I hereby claim:
* I am albertodebortoli on github.
* I am albertodebortoli (https://keybase.io/albertodebortoli) on keybase.
* I have a public key whose fingerprint is 40AC D3BB CE5F 75CC 3836 9084 BF11 3F8F 2F64 3DCA
To claim this, I am signing this object:
@albertodebortoli
albertodebortoli / getTabBarItemView.m
Created August 14, 2015 09:37
Get the tabbar item view.
+ (UIView *)viewForTabInTabBar:(UITabBar* )tabBar withIndex:(NSUInteger)index
{
NSMutableArray *tabBarItems = [NSMutableArray arrayWithCapacity:[tabBar.items count]];
for (UIView *view in tabBar.subviews) {
if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")] && [view respondsToSelector:@selector(frame)]) {
// check for the selector -frame to prevent crashes in the very unlikely case that in the future
// objects thar don't implement -frame can be subViews of an UIView
[tabBarItems addObject:view];
}
}
@albertodebortoli
albertodebortoli / change_author_git_commit.md
Last active November 10, 2023 08:41
Change the author of a commit in Git

Using Interactive Rebase

git rebase -i -p <some HEAD before all of your bad commits>

Then mark all of your bad commits as "edit" in the rebase file, and when git asks you to amend each commit, do

git commit --amend --author "New Author Name <[email protected]>"

edit or just close the editor that opens, and then do

@albertodebortoli
albertodebortoli / gist:a73154bdc77ae3d6c539
Created May 12, 2015 18:45
Fix Xcode 6.3.1 installing on device code signing problem.
rm -rf ~/Library/Developer/Xcode/DerivedData/JUSTEAT-*/Build/Products/Debug-iphoneos/*.appex/
@albertodebortoli
albertodebortoli / gist:a9c3d4c76121f5b0677d
Created March 30, 2015 08:40
Reset all iOS simulators
if pgrep "iOS Simulator"; then
killall "iOS Simulator"
fi
if pgrep "Xcode"; then
killall "Xcode"
fi
xcrun simctl list | awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' | grep '^[-A-Z0-9]*$' | xargs -I uuid xcrun simctl erase uuid | true
echo $?