Skip to content

Instantly share code, notes, and snippets.

View MP0w's full-sized avatar
🏍️

Alex Manzella MP0w

🏍️
View GitHub Profile
@MP0w
MP0w / gist:8216753
Created January 2, 2014 09:19
Fix iOS 7 texview that doesn't scroll properly while you type
- (void)textViewDidChange:(UITextView *)textView {
CGRect line = [textView caretRectForPosition:
textView.selectedTextRange.start];
CGFloat overflow = line.origin.y + line.size.height
- ( textView.contentOffset.y + textView.bounds.size.height
- textView.contentInset.bottom - textView.contentInset.top );
if ( overflow > 0 ) {
CGPoint offset = textView.contentOffset;
offset.y += overflow + 7;
[UIView animateWithDuration:.2 animations:^{
@MP0w
MP0w / gist:8527677
Created January 20, 2014 19:47
Pluck?
//place a button somewhere and add a target with selector showMusic:
//....
-(void)showMusic:(UIButton *)aButtonPlacedSomewhere{
MPMediaPickerController* picker=[[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
picker.showsCloudItems=YES;
picker.allowsPickingMultipleItems=YES;
picker.delegate=self;
[self presentViewController:picker animated:NO completion:NULL];
}
@MP0w
MP0w / gist:11351182
Created April 27, 2014 17:37
2048 is not enough...
// cheat in the game 2048
// cheat is not funny so don't compile to cheat
// so why I did?
// what is funny is to make the cheat, not to play with it =)
// how to get headers of App Store Apps ?
// https://github.com/MP0w/dumpdecrypted
@interface ViewController: NSObject
- (void)cheat;
@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)
}
@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 / 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: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
//
// 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: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 = @"\\[(.*?)\\]";
@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]