Skip to content

Instantly share code, notes, and snippets.

@berikv
berikv / gist:1442391
Created December 7, 2011 10:55
GCD timer in a UIViewController
@interface MyViewController()
@property (nonatomic, assign) dispatch_source_t timer;
- (void)handleTimer;
@end
@implementation
@synthesize timer=timer_;
- (id)init {
@berikv
berikv / gist:1761420
Created February 7, 2012 19:35
Remove files from git history
toRemove='someDirectory/* bigFile.txt'
# Remove every file that matches $toRemove
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch $toRemove" --prune-empty -- --all
# Rebuild the history cache (does not seem to remove big file from the git caches... maybe not required)
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
# Make a clean clone
@berikv
berikv / gist:3032992
Created July 2, 2012 12:26
My tools for webservice debugging
# First install LWP
sudo cpan install LWP
# Then add some aliasses, add them to your shell's startup script
lwpOptions="-uUsSe"
alias GET="lwp-request -m GET $lwpOptions"
alias POST="lwp-request -m POST $lwpOptions"
alias HEAD="lwp-request -m HEAD $lwpOptions"
# Now use them:
@berikv
berikv / NSString+split.h
Created January 25, 2013 13:32
NSString+split
// Based upon: http://stackoverflow.com/a/13839284/439096
#import <Foundation/Foundation.h>
@interface NSString (split)
@property (nonatomic, readonly) NSArray *split;
@end
@berikv
berikv / xcode_shortcuts.md
Last active December 14, 2015 14:18
My favourite XCode shortcuts

Running

  • Run: command+r
  • Stop: command+.
  • Run without building: command+control+r
  • Test: command+u
  • Analyse: command+shift+b
  • Clean: command+shift+k
  • Super-clean: command+alt+shift+k
@berikv
berikv / updateRunningAverage
Last active December 15, 2015 02:19
Running average as implemented in the Linux/Unix kernels (shown with the `w` command). Usages can be frame rate, accelerometer, etc.
// A factor of 0.5 means that every newValue will have a 50% impact on the average
// Usage: self.average = updateRunningAverage(self.average, newValue, 0.3);
#define updateRunningAverage(average, newValue, factor) (((newValue) * (factor)) + ((average) * (1.0 - (factor))))
@berikv
berikv / UIResponder+sendAction.h
Last active December 15, 2015 07:10
UIResponder sendAction
//
// UIResponder+sendAction.h
// Berik Visschers
//
// Created by Berik Visschers on 2013-03-22.
// Copyright (c) 2013 Xaton. All rights reserved.
//
#import <UIKit/UIKit.h>
@berikv
berikv / heading.py
Last active May 6, 2018 21:24 — forked from timtrueman/heading.py
- Fix wrap to allow for bigger angles - Replace the hardcoded declination correction with an argument
def wrap(angle):
while angle > 2 * pi:
angle -= 2 * pi
while angle < 0:
angle += 2 * pi
return angle
def magnetometer_readings_to_tilt_compensated_heading(bx, by, bz, phi, theta, declinationRadians=0):
""" Takes in raw magnetometer values, pitch and roll and turns it into a tilt-compensated heading value ranging from -pi to pi (everything in this function should be in radians).
The correct value for declinationRadians can be found online: http://magnetic-declination.com/countries.php note that this value is in radians, not in degrees.
@berikv
berikv / gist:6765119
Last active December 24, 2015 07:39
Check iOS version
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
// But only in XCode 5
@berikv
berikv / networkActivityIndicator
Last active August 29, 2015 14:09
Multiple concurrent networkActivityIndicators
var applicationActivityIndicators = 0
extension UIApplication {
func startActivityIndicator() {
applicationActivityIndicators++
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
}
func stopActivityIndicator() {
applicationActivityIndicators--
if applicationActivityIndicators <= 0 {