Skip to content

Instantly share code, notes, and snippets.

David Fox dfox

Block or report user

Report or block dfox

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dfox
dfox / cakeConfig.scala
Last active Dec 24, 2015
Externalizing configuration values using the Cake Pattern
View cakeConfig.scala
/* Standard component trait a-la cake */
trait MessagePrinterComponent {
def printer: MessagePrinter
trait MessagePrinter{
def printMessage(message: String)
}
}
@dfox
dfox / event-logger.m
Created Aug 7, 2012
The EventLogger Class
View event-logger.m
#import "EventLogger.h"
NSString *const EVENT_LOGGER_APPEARED = @"appeared";
NSString *const EVENT_LOGGER_TOUCHED = @"touched";
@implementation EventLogger
+(void)logEvent:(NSString *)type forObject:(NSObject *)object
{
if ([object respondsToSelector:@selector(eventValue)]
@dfox
dfox / uiviewcontroller-method-swizzling.m
Created Aug 7, 2012
Method Swizzling in UIApplication to Capture viewDidAppear:
View uiviewcontroller-method-swizzling.m
#import "UIViewController+EventInterceptor.h"
#import "EventLogger.h"
#import <objc/runtime.h>
@implementation UIViewController (EventInterceptor)
+(void) load
{
//Replace the noop viewDidAppear with our own implementation
class_replaceMethod(self, @selector(viewDidAppear:), (IMP) viewDidAppear, "v@:@");
@dfox
dfox / uiapplication-method-swizzling.m
Created Aug 7, 2012
Method Swizzling in UIApplication to Capture Touch Events
View uiapplication-method-swizzling.m
#import "UIApplication+EventInterceptor.h"
#import <objc/runtime.h>
#import "EventLogger.h"
@implementation UIApplication (EventInterceptor)
+(void) load
{
//Swap the implementations of our interceptor and the original sendEvent:
Method oldMethod = class_getInstanceMethod(self, @selector(sendEvent:));
@dfox
dfox / adding-properties-to-uiresponder.m
Created Aug 7, 2012
Adding Properties to UIResponder
View adding-properties-to-uiresponder.m
#import "UIResponder+EventInterceptor.h"
#import <objc/runtime.h>
const char *ASSOC_OBJECT_EVENT_TYPE = "eventType";
const char *ASSOC_OBJECT_EVENT_VALUE = "eventValue";
@implementation UIResponder (EventInterceptor)
-(void) setEventValue:(NSString *)eventValue
{
@dfox
dfox / update-route53-dns.sh
Created Jan 25, 2012
A script to update DNS on Route 53
View update-route53-dns.sh
#!/bin/sh
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Load configuration
. /etc/route53/config
@dfox
dfox / update-route53-dns-config.sh
Created Jan 25, 2012
Configuration file for the Route 53 update script
View update-route53-dns-config.sh
AWS_ACCESS_KEY_ID="<Your access key ID>"
AWS_SECRET_ACCESS_KEY="<Your secret access key>"
ZONE="<The name of your subdomain>"
TTL="600"
@dfox
dfox / route53-user-policy.json
Created Jan 25, 2012
An IAM policy for Amazon AWS to allow limited access to Route 53
View route53-user-policy.json
{
"Statement":[
{
"Action":[
"route53:ChangeResourceRecordSets",
"route53:GetHostedZone",
"route53:ListResourceRecordSets"
],
"Effect":"Allow",
"Resource":[
@dfox
dfox / AsynchronousTaskTest.java
Created Apr 27, 2011
A unit test for a contrived asynchronous example class
View AsynchronousTaskTest.java
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Test;
public class AsynchronousTaskTest implements Callback {
private CountDownLatch latch;
public void completed() {
@dfox
dfox / AsynchronousTask.java
Created Apr 27, 2011
A contrived asynchronous example class
View AsynchronousTask.java
public interface Callback {
void completed();
}
public class AsynchronousTask extends Thread {
private Callback callback;
private int result;
public AsynchronousTask(final Callback callback){
You can’t perform that action at this time.