Skip to content

Instantly share code, notes, and snippets.

View leviathan's full-sized avatar

Jörg Polakowski leviathan

  • Lund, Sweden
  • 01:19 (UTC +02:00)
View GitHub Profile
@leviathan
leviathan / force-reset-git-branch
Created October 18, 2017 13:01
Force reset git branch
git checkout develop
git pull origin develop
git checkout stage
git reset --hard develop
git push origin stage --force-with-lease
@leviathan
leviathan / NSObject+ClassMethodList.m
Created January 20, 2016 09:10
Find properties as strings of a Class
/**
* Determines the properties of @c className and returns list of these properties as strings.
* The method will iterate through @c className superclass hierarchy and fetch the properties from
* the superclass hierarchy as well.
*
* @return the list of properties found on @c className
*/
- (NSOrderedSet<NSString *> *)getMethodListForClass:(Class)className
{
NSMutableOrderedSet<NSString *> *propertiesList = [NSMutableOrderedSet orderedSet];
@leviathan
leviathan / DiscoverAppModuleClasses.m
Last active August 29, 2015 14:05
Object discovery
#import <objc/runtime.h>
- (NSArray *)discoverAppModuleClasses
{
NSMutableArray *appModuleClasses = [NSMutableArray array];
// Integrate all classes which comply to the provider protocol
unsigned int count = 0;
Class *classList = objc_copyClassList(&count);
for (NSUInteger index = 0; index < count; index++)
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2013 Peter Steinberger. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.
__weak __typeof__(self) weakSelf = self;
// some api that takes blocks, when you give the block do
^{
__strong __typeof__(weakSelf) self = weakSelf;
}
@leviathan
leviathan / UIKit+Benchmark.h
Created January 14, 2014 13:13
UIKit Benchmarking Drawing
CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(refresh:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
counter = 0;
previousTimestamp = displayLink.timestamp;
- (void)refresh:(CADisplayLink *)displayLink {
counter++;
if (counter > 60) {
@leviathan
leviathan / UICustomTableViewController.m
Created December 5, 2013 07:29
UITableViewCell scaling animation
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// setup initial state (e.g. before animation)
cell.layer.shadowColor = [[UIColor blackColor] CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
cell.alpha = 0;
cell.layer.transform = CATransform3DMakeScale(0.5, 0.5, 0.5);
cell.layer.anchorPoint = CGPointMake(0, 0.5);
// define final state (e.g. after animation) & commit animation
[UIView beginAnimations:@"scaleTableViewCellAnimationID" context:NULL];
@leviathan
leviathan / UIImage+Offscreen.m
Last active May 10, 2023 17:50
UIImage offscreen rendering
// Define callback blocks
// Success
__block typeof (self) weakSelf = self;
void (^successBlock)(NSURLRequest *, NSHTTPURLResponse *, UIImage *) =
^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
// Assigning an image that has not yet been decoded leads
// to stuttering in UI animations
// Forcing image decoding on a background thread fixes this
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^(void) {
@leviathan
leviathan / mountain-lion-brew-setup.markdown
Created September 27, 2012 09:17 — forked from myobie/mountain-lion-brew-setup.markdown
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

// Initialize namespaces ---------------------
if (!window.mm) {
mm = {};
}
// avoid window. use this if you "think" you are in root closure. makes encapsulation possible and code executable without DOM (like node...)
if (!this.mm) {
mm = {};
}