Skip to content

Instantly share code, notes, and snippets.

View erikkerber's full-sized avatar
📱
One of the "OK" ones

Erik Kerber erikkerber

📱
One of the "OK" ones
View GitHub Profile
// Ensures the shake is strong enough on at least two axes before declaring it a shake.
// "Strong enough" means "greater than a client-supplied threshold" in G's.
static BOOL L0AccelerationIsShaking(UIAcceleration* last, UIAcceleration* current, double threshold) {
double
deltaX = fabs(last.x - current.x),
deltaY = fabs(last.y - current.y),
deltaZ = fabs(last.z - current.z);
return
(deltaX > threshold && deltaY > threshold) ||
@erikkerber
erikkerber / ResourceHelper.cs
Created July 31, 2012 13:32
MonoDroid Resource to FileSystem management
using System;
using System.Collections.Generic;
using Android.Content.Res;
using System.Resources;
using System.IO;
using Android.Content;
using Android.App;
namespace AndroidSandbox
{
@erikkerber
erikkerber / gist:4974871
Created February 18, 2013 02:55
Hadoop build script.
<!DOCTYPE project>
<project name="SEIS785Project" default="main" basedir=".">
<!-- load properties file -->
<property file="build.properties" />
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
// clang -fobjc-arc -framework Foundation runtime-class.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Person : NSObject
- (id)initWithFirstName: (NSString *)firstName lastName: (NSString *)lastName age: (NSUInteger)age;
#import <objc/runtime.h>
- (BOOL) objectsAreEqual:(NSObject *)o1 objectTwo:(NSObject *)o2 {
if([o1 class] != [o2 class]) return NO;
NSUInteger property_count;
objc_property_t * property_list = class_copyPropertyList([o1 class], &property_count); // Must Free, later
for (int i = 0; i <= property_count ; i++) { // Reverse order, to get Properties in order they were defined
@erikkerber
erikkerber / UIViewController+RecursiveDescription.m
Last active December 31, 2015 04:29
Recursive viewcontroller description
#import "UIViewController+RecursiveDescription.h"
@implementation UIViewController (RecursiveDescription)
-(NSString*)recursiveDescription
{
NSMutableString *description = [NSMutableString stringWithFormat:@"\n"];
[self addDescriptionToString:description indentLevel:0];
return description;
}
// As a local variable.
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
// As a property.
@property (nonatomic, copy) returnType (^blockName)(parameterTypes);
// As a method parameter.
- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName {...}
// As an argument to a method call.
/*
* Example usage
*
* id<MyProtocol> mockProtocol = [DynamicObject new];
*
* mockProtocol.mockProperty = SomeEnum;
* mockProtocol.mockString = @"Foo";
*
*/
@erikkerber
erikkerber / Mac Bootstrap.md
Last active December 12, 2018 02:38
Steps for bootstrapping a new mac

Apps to install from macOS App Store:

  • Tweetbot
  • Pastebot
  • 1Password
  • Spark
  • Things
  • Bear
  • Slack
  • Annotate
{"version":1,"resource":"file:///Users/ekerber/dev/slack/slack-objc/bazel/tests.bzl","entries":[{"id":"BP4O.bzl","timestamp":1658882739917}]}