Skip to content

Instantly share code, notes, and snippets.

View albertodebortoli's full-sized avatar
👶

Alberto De Bortoli albertodebortoli

👶
View GitHub Profile
@albertodebortoli
albertodebortoli / gist:67d0d4522400193aa521
Created November 28, 2014 21:18
UICollectionView: Paging for Smaller Width Cells
// NOTE: This delegate method requires you to disable UICollectionView's `pagingEnabled` property.
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset {
CGPoint point = *targetContentOffset;
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
// This assumes that the values of `layout.sectionInset.left` and
@albertodebortoli
albertodebortoli / remove_git_submodule
Last active October 26, 2016 18:25
How to remove a git submodule
Steps to safely remove a git submodule:
1. Delete the relevant section from the .gitmodules file
2. Stage the .gitmodules changes git add .gitmodules
3. Delete the relevant section from .git/config
4. Run git rm --cached path_to_submodule
5. Run rm -rf .git/modules/path_to_submodule
6. Commit git commit -m "Removed submodule <name>"
7. Delete the now untracked submodule files rm -rf path_to_submodule
@albertodebortoli
albertodebortoli / .gitignore
Created August 1, 2014 23:07
.gitignore for Xcode projects in 2014
# Xcode
build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
@albertodebortoli
albertodebortoli / TrackingScrollView
Created July 30, 2014 17:13
Something that will be handly sooner of later.
+ (UIScrollView *)_trackingScrollView:(id)selfObject {
if ([selfObject respondsToSelector:@selector(trackingScrollView)]) {
return objc_msgSend(selfObject, @selector(trackingScrollView));
}
unsigned int proprtiesCount;
objc_property_t *properties = class_copyPropertyList([self class], &proprtiesCount);
for (int i = 0; i < proprtiesCount; i++) {
@albertodebortoli
albertodebortoli / property_type.m
Created July 30, 2014 11:10
Get the type of a property.
static const char *getPropertyType(objc_property_t property) {
const char *attributes = property_getAttributes(property);
char buffer[1 + strlen(attributes)];
strcpy(buffer, attributes);
char *state = buffer, *attribute;
while ((attribute = strsep(&state, ",")) != NULL) {
if (attribute[0] == 'T' && attribute[1] != '@') {
NSString *name = [[NSString alloc] initWithBytes:attribute + 1 length:strlen(attribute) - 1 encoding:NSASCIIStringEncoding];
return (const char *)[name cStringUsingEncoding:NSASCIIStringEncoding];
}
git shortlog -s -n
git log --author="__YOUR_NAME_HERE__" --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
@albertodebortoli
albertodebortoli / unit_test_snippet
Created May 6, 2014 19:27
Xcode Unit Test snippet
- (void)test_Given<#state#>_When<#action#>_Then<#result#> {
XCTAssert();
}
@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 / 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 / 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;