Skip to content

Instantly share code, notes, and snippets.

@joshavant
joshavant / gist:1637633
Created January 19, 2012 03:41
My Open Source License: MIT Expat + Beerware
Copyright (c) <year> Josh Avant
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@joshavant
joshavant / gist:3355530
Created August 15, 2012 03:45
Apple-safe UUID Generation
// requires UICKeyChainStore lib
NSString *uniqueIdentifier;
#if TARGET_IPHONE_SIMULATOR
uniqueIdentifier = @"SIMULATOR";
#else
uniqueIdentifier = [UICKeyChainStore stringForKey:@"UUID" service:@"joshavant"];
if(![uniqueIdentifier length] > 0)

When I fork repos, I often like to keep my personal fork neat and clean, containing only branches that I personally implement.

Given that, I fork and then delete all of the original branches that come from the parent repo (but keep the master branch, since GitHub requires a branch that acts as a main, 'master' branch).

  1. Fork the branch on GitHub
  2. $ git remote add forkName git@github.com:joshavant/Foobar.git
  3. $ git fetch forkName
  4. $ git branch -r | grep forkName | sed 's/ forkName\///' | grep -v '^[[:space:]]*master[[:space:]]*$' | while read line ; do git push forkName --delete $line ; done
@joshavant
joshavant / page_monitor.sh
Created March 15, 2013 00:39
page_monitor.sh
#!/usr/bin/env bash
# Super quick-n-dirty, cronable bash script to monitor webpage changes and notify via email
# Discussion:
# For every site, sanity check this whole script by running it twice while the page hasn't changed.
# (Due to md5 hashing, this script won't work with any site that serves up a dynamic content body.)
#
# The host must be able to send email via `mail`.
# I used this guide to get up and running in ~5 minutes:
@joshavant
joshavant / gist:5314853
Last active December 15, 2015 19:59
.delegate MitM Proxying

.delegate MitM Proxying

Overview

This is a quick and easy way to insert yourself as a .delegate man-in-the-middle for protocol methods. External to your class, the .delegate property can be used as normal, and all method calls will filter through, as if nothing has changed.

A benefit of this method over swizzling is that it will keep proxying behavior contained to the subclass that implements this, and not all instances of the parent class.

License

This is licensed under a MIT/Beerware License:

@joshavant
joshavant / branch_to_fork.md
Created April 22, 2013 21:53
branch_to_fork.md

Creates a new branch on a secondary Git repo (i.e. fork) with the contents of a branch from a primary repo:

git fetch SOURCE_REMOTE SOURCE_BRANCH:NEW_BRANCH_NAME; git checkout NEW_BRANCH_NAME; git branch -u TARGET_REMOTE NEW_BRANCH_NAME

i.e. git fetch origin 3.7.0:foobar-feature; git checkout foobar-feature; git branch -u fork foobar-feature

@joshavant
joshavant / button.md
Created July 9, 2013 01:36
Quick debug button for iOS apps

Copy-and-paste this over the last few lines of application:didFinishLaunchingWithOptions:

  UIButton *debugButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  debugButton.frame = CGRectMake(0.f, 20.f, 44.f, 44.f);
  [debugButton addTarget:self action:@selector(didPressDebugButton) forControlEvents:UIControlEventTouchUpInside];
  [self.window addSubview:debugButton];

  return YES;  

}

@joshavant
joshavant / privacy.md
Created August 9, 2013 00:22
Current HoR Members Supporting Privacy

###Current members of the House of Representatives who voted: NO - PATRIOT Act
NO - 2005 Reauthorization of PATRIOT Act
NO - 2006 Reauthorization of PATRIOT Act
NO - 2011 Reauthorization of PATRIOT Act
YES - Amash Amendment

  • Rep. Michael Capuano [D-MA7]
  • Rep. Elijah Cummings [D-MD7]
  • Rep. Danny Davis [D-IL7]
@joshavant
joshavant / observer_pattern.md
Created April 17, 2014 22:04
Handy little design pattern that lets you kick off processes in arbitrary objects + lets arbitrary dependencies add themselves into a notification chain

##XXAppDelegate.m, XXSomeView.m, some other object, etc##

...
[[XXSomeSingletonController sharedInstance] doThatThing];
...

##XXSomeSingletonControllerObserver.h##

@protocol XXSomeSingletonControllerObserver 
@joshavant
joshavant / Foo.m
Created May 13, 2014 20:48
Thread-safe, forced initialization for singletons
#import "Foo.h"
static dispatch_once_t FooSharedDispatchOnceToken;
static Foo *FooSharedInstance;
+ (void)prepareService
{
[self fetchSharedServiceAndInitialize:YES];
}