Skip to content

Instantly share code, notes, and snippets.

View nuthatch's full-sized avatar

Stephen Ryner Jr. nuthatch

View GitHub Profile
@nuthatch
nuthatch / TouchyWebView.java
Created February 5, 2012 19:29
Android: If you're going to embed a WebView that responds to touch events inside a ScrollView or other touch consumer, you need to override onTouchEvent to requestDisallowInterceptTouchEvent and prevent the parent from stealing your events. Do it!
static final class TouchyWebView extends WebView
{
public TouchyWebView(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event){
requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(event);
@nuthatch
nuthatch / iOS 7 dynamic font mappings
Last active January 9, 2023 13:55
What is UIFontTextStyleHeadline *really*? Dump out preferredFontForTextStyle for UIFontTextStyleHeadline, UIFontTextStyleSubheadline, UIFontTextStyleBody, UIFontTextStyleFootnote, UIFontTextStyleCaption1, UIFontTextStyleCaption2 to examine the font name, weight, and point size.
+ (void)describePreferredFonts
{
static NSArray *textStyles;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
textStyles = @[UIFontTextStyleHeadline,
UIFontTextStyleSubheadline,
UIFontTextStyleBody,
UIFontTextStyleFootnote,
UIFontTextStyleCaption1,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>shortcut</key>
<string>:smile:</string>
<key>phrase</key>
<string>😄</string>
</dict>
@nuthatch
nuthatch / preferred Content Size description
Created November 22, 2013 03:46
Map preferredContentSizeCategory into a human-readable string, e.g. UIContentSizeCategoryAccessibilityMedium becomes "Accessibility Medium"
+ (NSString *)preferredContentSizeDescription
{
// see http://johnszumski.com/blog/implementing-dynamic-type-on-ios7
NSString *contentSize = [UIApplication sharedApplication].preferredContentSizeCategory;
NSString *description;
if ([contentSize rangeOfString:@"Accessibility"].location != NSNotFound)
{
// Accessibility Content Size Category Constants
@nuthatch
nuthatch / fix macOS.bash
Created August 11, 2019 20:25
The three macOS preferences I always set on a new machine: no desktop, no drop shadows in screenshots, and clicking app in Dock hides all other apps
#!/bin/bash
# hide Desktop clutter (Desktop is just a folder in Finder)
defaults write com.apple.finder CreateDesktop false
killall Finder
# enable "Purple Button Mode"
# see https://tidbits.com/2009/10/06/revealing-mac-os-xs-hidden-single-application-mode/
defaults write com.apple.dock single-app -bool true
killall Dock
@nuthatch
nuthatch / NSManagedObject+Serialization.h
Last active May 8, 2019 11:25 — forked from pkclsoft/NSManagedObject+Serialization.h
Fixes for Peter Easdown's category 1. don't assume each Entity name matches the Class name. 2. strip DATE_ATTR_PREFIX when deserializing dates back into NSManagedObject 3. add support for NSOrderedSet 4. use set to keep traversal history, and allow classes to opt-out with serializationObjectsToSkip
@interface NSManagedObject (Serialization)
- (NSDictionary*) toDictionary;
- (void) populateFromDictionary:(NSDictionary*)dict;
+ (NSManagedObject*) createManagedObjectFromDictionary:(NSDictionary*)dict
inContext:(NSManagedObjectContext*)context;
@end
@nuthatch
nuthatch / gist:983606
Created May 20, 2011 19:31
set Typeface to all TextViews in a ViewGroup for Android
// recursively apply typeface to our textviews
static final void setTypeface(ViewGroup viewGroup, Typeface typeface)
{
if (viewGroup == null) return;
int children = viewGroup.getChildCount();
Log.d(TAG, "setTypeface " + viewGroup + " : " + children);
for (int i=0; i<children; i++)
{
View view = viewGroup.getChildAt(i);
@nuthatch
nuthatch / iOS 9 Dynamic Font Mappings
Last active June 14, 2016 08:40
iOS 9 replaces Helvetica Nue with the new San Francisco font
- (void)describePreferredFonts
{
static NSArray *textStyles;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
textStyles = @[UIFontTextStyleTitle1, // iOS 9
UIFontTextStyleTitle2, // iOS 9
UIFontTextStyleTitle3, // iOS 9
UIFontTextStyleHeadline,
UIFontTextStyleSubheadline,
Chinese (Simplified)
China (CN)
Chinese (Traditional)
Taiwan (TW)
Macau (MO)
Danish
Denmark (DK)
@nuthatch
nuthatch / bad-traceroute.txt
Created December 1, 2013 17:00
ping times at 10:57 CST on Sunday, December 1st
~ $ traceroute comcast.net
traceroute: Warning: comcast.net has multiple addresses; using 69.252.80.75
traceroute to comcast.net (69.252.80.75), 64 hops max, 52 byte packets
1 10.0.1.1 (10.0.1.1) 1.005 ms 0.632 ms 0.664 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *