Skip to content

Instantly share code, notes, and snippets.

View jdewind's full-sized avatar

Justin DeWind jdewind

  • LifeWorks
  • Grand Rapids
View GitHub Profile
@jdewind
jdewind / gist:2470996
Created April 23, 2012 13:41
Pick Mirrored Route
@implementation MyClass
- (void)pickAMirroredRoute {
MPAudioDeviceController *audoDeviceController = [[MPAudioDeviceController alloc] init];
audoDeviceController.routeDiscoveryEnabled = YES;
[audoDeviceController determinePickableRoutesWithCompletionHandler:^(NSInteger value) {
NSMutableArray *routes = [NSMutableArray array];
[audoDeviceController clearCachedRoutes];
NSUInteger index = 0;
@jdewind
jdewind / gist:1204051
Created September 8, 2011 17:41
Capture the entire contents of a UITableView or UIScrollView
static UIImage* CreateImageFromView(UITableView *view)
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(view.contentSize.width, view.contentSize.height), NO, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect previousFrame = view.frame;
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.contentSize.width, view.contentSize.height);
[view.layer renderInContext:context];
view.frame = previousFrame;
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@jdewind
jdewind / EventBusOnGuiceRoids.java
Created January 13, 2012 14:59
EventBus on GuiceRoids
public class ApplicationModule extends AbstractModule {
private final EventBus eventBus = new EventBus("Default EventBus");
@Override
protected void configure() {
bind(EventBus.class).toInstance(eventBus);
bindListener(Matchers.any(), new TypeListener() {
public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) {
typeEncounter.register(new InjectionListener<I>() {
public void afterInjection(I i) {
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a" &&
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" &&
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal" &&
UNIVERSAL_LIBRARY_PATH="${UNIVERSAL_LIBRARY_DIR}/${PRODUCT_NAME}" &&
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${PRODUCT_NAME}.framework" &&
# Create framework directory structure.
rm -rf "${FRAMEWORK}" &&
mkdir -p "${UNIVERSAL_LIBRARY_DIR}" &&
mkdir -p "${FRAMEWORK}/Versions/A/Headers" &&
@jdewind
jdewind / gist:2467675
Created April 23, 2012 00:12
iOS mirroring selection
// Make sure MediaPlayer.framework has been added and the MPAudioVideoRoutingPopoverController interface has been declared.
@interface MyViewController ()
@property (strong, nonatomic) MPAudioVideoRoutingPopoverController *airplayPopoverController;
@end
- (void)someButtonTapped:(id)sender {
self.airplayPopoverController = [[MPAudioVideoRoutingPopoverController alloc] initWithType:0 includeMirroring:YES];
self.airplayPopoverController.delegate = self;
[self.airplayPopoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
public class RefreshEntityInterceptor implements MethodInterceptor {
@Inject
private Provider<EntityManager> entityManagerProvider;
@Inject
protected Logger logger;
@SuppressWarnings("unchecked")
function doTap(x, y, numTaps, delay)
delay = delay or 16000;
local fingerId = 1;
for i=numTaps,1,-1
do
touchDown(fingerId, x, y);
usleep(delay);
touchUp(fingerId, x, y);
usleep(delay);
end
@jdewind
jdewind / DelegateExample.m
Last active January 4, 2016 17:19
ReactiveCocoaDelegateExample
- (void)viewDidLoad {
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame: CGRectZero];
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchController.delegate = self;
// Place it in view
searchBar.delegate = self;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text {
self.searchResults = [self search: text];
class MyViewController < UIViewController
def viewDidLoad
@search_bar = UISearchBar.alloc.initWithFrame CGRectZero
self.navigationController.rac_liftSelector "setNavigationBarHidden:animated:", withSignalsFromArray: [@search_bar.rac_editing, RACSignal.return(true)]
# Add search bar to table view, etc.
end
end
@implementation UISearchBar (RAC)
- (RACSignal *)rac_editing {
// Pretend we have an ivar I know we'd use setAssociatedObject
_proxy = [[RACDelegateProxy alloc] initWithProtocol: @protocol(UISearchBarDelegate)];
return [@[
[[_proxy signalForSelector: @selector(searchBarTextDidBeginEditing:)] mapReplace: @YES],
[[_proxy signalForSelector: @selector(searchBarTextDidEndEditing:)] mapReplace: @NO]
].rac_sequence.signal switchToLatest];
}
@end