Skip to content

Instantly share code, notes, and snippets.

View albertodebortoli's full-sized avatar
👶

Alberto De Bortoli albertodebortoli

👶
View GitHub Profile
@interface NSFileManager (DoNotBackup)
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;
@end
@albertodebortoli
albertodebortoli / UIView+ADBSubviews.h
Created September 21, 2013 20:18
Find the first view of a given class in the iOS7 subviews hierarchy. iOS backward compatible.
//
// UIView+ADBSubviews.h
// iHarmony
//
// Created by Alberto De Bortoli on 06/08/13.
// Copyright (c) 2013 iHarmony. All rights reserved.
//
#import <UIKit/UIKit.h>
@albertodebortoli
albertodebortoli / gist:6910168
Last active December 25, 2015 03:29
Compare string versions
+ (BOOL)currentVersionIsGreaterOrEqualThan:(NSString *)baseVersion
{
// baseVersion is something like @"1.0.5"
NSArray *baseVersionComponents = [baseVersion componentsSeparatedByString:@"."];
NSString *version = [UIDevice currentDevice].systemVersion;
NSArray *components = [version componentsSeparatedByString:@"."];
// the number of components of both version must be the same
for (int i = 0; i < [components count]; i++) {
@albertodebortoli
albertodebortoli / gist:8645930
Last active January 4, 2016 16:09
Macro to test asynchronous Objective-C code
#define FutureConditionToBreakWithTimeout(_condition_, _duration_) \
NSDate *loopUntil = [NSDate dateWithTimeIntervalSinceNow:_duration_]; \
while (!_condition_ && [loopUntil timeIntervalSinceNow] > 0) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:loopUntil]; \
}
@albertodebortoli
albertodebortoli / MoreWarnings.xcconfig
Created February 10, 2014 23:58
MoreWarnings.xcconfig
//
// MoreWarnings.xcconfig
//
// Created by Steven Fisher:
// http://tewha.net/2010/11/xcode-warnings/
// See also:
// http://boredzo.org/blog/archives/2009-11-07/warnings
//
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
@albertodebortoli
albertodebortoli / linux-snippets.md
Last active August 29, 2015 13:56
Linux Snippets

Linux - Snippets

by Marco Cattai

Searching

Search all the files/folder with that name and remove them

find . -name "FILE-TO-FIND"-exec rm -rf {} \;

@albertodebortoli
albertodebortoli / blurFacebookProfileimage.m
Last active August 29, 2015 13:56
Blur the Facebook Profile image retrieved with the Facebook SDK
self.profilePictureView.profileID = user.id;
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UIImageView *imageView = nil;
for (UIView *subview in [self.profilePictureView subviews]) {
if ([subview isKindOfClass:[UIImageView class]]) {
imageView = (UIImageView *)subview;
@albertodebortoli
albertodebortoli / generate_toc.rb
Last active April 7, 2022 14:14
Generate Markdown TOC
#!/usr/bin/env ruby
File.open("your_file.md", 'r') do |f|
f.each_line do |line|
forbidden_words = ['Table of contents', 'define', 'pragma']
next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ }
title = line.gsub("#", "").strip
href = title.gsub(" ", "-").downcase
puts " " * (line.count("#")-1) + "* [#{title}](\##{href})"
@albertodebortoli
albertodebortoli / concurrency-trivia.m
Last active August 29, 2015 13:57
Objective-C Concurrency/Threading/GCD Trivia
@synchronized(self) {
NSLog(@"%i", 1);
dispatch_queue_t queue = dispatch_queue_create("com.albertodebortoli.serial_queue", DISPATCH_QUEUE_SERIAL);
dispatch_sync(queue, ^{
NSLog(@"%i", 2);
@synchronized(self) {
NSLog(@"%i", 3);
}
NSLog(@"%i", 4);
});
@albertodebortoli
albertodebortoli / unit_test_snippet
Created May 6, 2014 19:27
Xcode Unit Test snippet
- (void)test_Given<#state#>_When<#action#>_Then<#result#> {
XCTAssert();
}