Skip to content

Instantly share code, notes, and snippets.

View MP0w's full-sized avatar
🏍️

Alex Manzella MP0w

🏍️
View GitHub Profile
@MP0w
MP0w / arrayOfRanges.swift
Created March 17, 2016 21:19
Compiler Infinite loop [SR-774]
let someRanges = [1..<4, 1..<8, 1..<16, 1..<32, 1..<64, 1..<128, 1..<256, 1..<512, 1..<1024]
@MP0w
MP0w / SILSegFault.swift
Created March 13, 2016 17:11
SIL segmentation fault (same crash as https://bugs.swift.org/browse/SR-358 , already fixed)
public protocol A {
func methodName()
}
extension A {
func methodName(differentParam: Any) {}
}
class Test: A {}
@MP0w
MP0w / MergeSort.playground
Created January 15, 2016 22:32
MergeSort playground
//: Playground - noun: a place where people can play
import UIKit
func mergeArrays<T: Comparable>(left: [T], _ right: [T]) -> [T] {
var leftIndex = 0
var rightIndex = 0
var orderedArray = [T]()
while leftIndex < left.count && rightIndex < right.count {
@MP0w
MP0w / Reveal Home Screen Quick Actions in Xcode 7 simulator
Created September 24, 2015 11:11
Xcode 7's simulator can't simulate 3D Touch, use cycript and this script to test your own app Raw
app = [[SBApplicationController sharedInstance] applicationWithBundleIdentifier:@"com.apple.mobilesafari"]
appIcon = [[SBApplicationIcon alloc] initWithApplication:app]
iconView = [[SBIconView alloc] init];
iconView.icon = appIcon;
iconController = choose(SBIconController)[0]
iconView.delegate = iconController
[iconController _revealMenuForIconView:iconView presentImmediately:1]
@MP0w
MP0w / gist:40d638a6105b55076377
Created May 4, 2015 17:16
Experimental Auto Layout short syntax (visual format)
// Usage example : [self addConstraintsWithVisualFormat:@"V:|-0-[myAwesomeView]-0-|", self.awesome, nil];
// no need to use underscore for property
// Actually would break with priority annotations but who care! It's just an experiment
// Not using NSDictionaryOfVariableBindings(...) to have easy use also in swift
- (void)addConstraintsWithVisualFormat:(NSString *)formatString,... NS_REQUIRES_NIL_TERMINATION {
va_list args;
va_start(args, formatString);
NSString *pattern = @"\\[(.*?)\\]";
//
// main.m
// swizzle
//
// Created by Alex Manzella on 04/07/14.
// Copyright (c) 2014 mpow. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@MP0w
MP0w / gist:6c14d32b55a4bc6e6624
Created July 3, 2014 12:45
fix iOS 7 popover presented from UIBarButtonItem(s)
// on iOS 7 present a popover from an UIBarButtonItem is buggy
// the arrow is not uncentered
// as always iOS 7 is broken setImageEdgeInsets
// try that
// the fix consist in setImageEdgeInsets:
- (UIBarButtonItem *)rightItem{
if (GBIsNativeiPad() && GBIsIOS7()) { // ios 7 sucks
@MP0w
MP0w / gist:75f70ff1d7287f31e22a
Created June 2, 2014 21:22
Already hating it
//
// ViewController.swift
// testSwift
//
// Created by Alex Manzella on 02/06/14.
// Copyright (c) 2014 mpow. All rights reserved.
//
import UIKit
@MP0w
MP0w / gist:8f206d153edc0ef36179
Created May 12, 2014 07:58
delete a line in known hosts
knownhosts () {
cp ~/.ssh/known_hosts ~/.ssh/known_hosts_$(date +%Y%m%d-%H%M%S) ;
sed -e "$1d" ~/.ssh/known_hosts > ~/.ssh/known_hosts_new ;
mv ~/.ssh/known_hosts_new ~/.ssh/known_hosts ;
chmod 644 ~/.ssh/known_hosts
}
@MP0w
MP0w / break delegates =)
Created May 6, 2014 12:31
break delegates =)
// I will not tell you why I made this, or you would think I am mad...
// But may be useful in future
//
// Yes is the equivalent of super.. but it's not allowed in categories
+ (void)load{
method_exchangeImplementations(class_getInstanceMethod(self, @selector(setDelegate:)), class_getInstanceMethod(self, @selector(hooked_setDelegate:))); // hook the setDelegate to hook it (later)
}