Skip to content

Instantly share code, notes, and snippets.

View albertodebortoli's full-sized avatar
👶

Alberto De Bortoli albertodebortoli

👶
View GitHub Profile
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 / 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];
}
@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 / .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 / 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 / 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 / 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 $?
@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 / 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@address.com>"

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

@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];
}
}