Skip to content

Instantly share code, notes, and snippets.

View gschandler's full-sized avatar

Scott Chandler gschandler

View GitHub Profile
@gschandler
gschandler / ClosureWeakifyStrongify.h
Created July 8, 2019 04:49
Objective-C weakify/strongify
#define weakify(var) __weak typeof(var) ClosureWeak_##var = var
#define strongify(var) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
__strong typeof(var) var = ClosureWeak_##var; \
_Pragma("clang diagnostic pop")
@gschandler
gschandler / gist:26a591eb550df74e787d
Created November 17, 2014 17:29
DNS failure workaround
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
@gschandler
gschandler / keywords.txt
Created January 30, 2014 08:12
Arduino library keywords.txt template, resides as a side-car next to the library source (C++ typically) files.
#######################################
# Syntax Coloring Map For <Arduino Library Name>
#######################################
# Class (KEYWORD1)
#######################################
MyClass KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
@gschandler
gschandler / battery.bat
Created September 30, 2013 06:32
Battery monitoring script
#!/bin/bash
MIN_LEVEL=40
MAX_LEVEL=80
CURRENT_LEVEL=`ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%d\n",$10/$5*100)}'`
if [ $CURRENT_LEVEL -lt $MIN_LEVEL ]; then
echo "Plug me back in, mate! ("$CURRENT_LEVEL"%)"
elif [ $CURRENT_LEVEL -gt $MAX_LEVEL ]; then
@gschandler
gschandler / WBVirtualKeyboardManager.m
Last active December 20, 2015 21:29
I have looked long and hard to find a way to force the virtual keyboard to appear while a BT keyboard (or other item emulating a KB) is active. This requires no private APIs or spelunking the view chain hierarchy to find some obscurely named keyboard view object. It makes a few assumptions, and so should not be considered a shining example of co…
// WBVirtualKeyboardManager.h
@interface WBVirtualKeyboardManager : NSObject
@property (assign, getter = shouldForceVirtualKeyboard) BOOL forceVirtualKeyboard;
+ (WBVirtualKeyboardManager *)sharedVirtualKeyboardManager;
- (void)activate;
- (void)deactivate;
@end
@gschandler
gschandler / WBMemory.h
Last active December 19, 2015 06:29
Retain/Release/Autorelease macros for using non-ARC code with an ARC project.
#ifdef __OBJC__
#ifndef WBRetain
#if __has_feature(objc_arc)
# define WBRetain(obj) obj
#else
# define WBRetain(obj) [obj retain]
#endif
#endif
@gschandler
gschandler / gist:5350807
Created April 10, 2013 00:53
Simple example of presenting an UINavigationController modally.
@interface SettingsViewController : UIViewController
@end
@interface MainViewController : UIViewController
- (IBAction)settingsButtonTapped:(id)sender;
@end
@implementation MainViewController
- (IBAction)settingsButtonTapped:(id)sender
{