Skip to content

Instantly share code, notes, and snippets.

View tewha's full-sized avatar

Steven Fisher tewha

  • 23:18 (UTC -07:00)
View GitHub Profile
@tewha
tewha / gist:1066123
Created July 5, 2011 22:34
animated error
- (void)showError;
{
dispatch_async( dispatch_get_main_queue(), ^ {
// Setup error view; these values are visible as it slides into place.
_errorView.alpha = finalErrorAlpha;
_errorLabel.text = [_error localizedDescription];
// Slide down the error view, with normal alpha.
[UIView animateWithDuration: slideDownDuration
animations: ^{
CGRect frame = _errorView.frame;
@tewha
tewha / complex-mapping-example.php
Created May 3, 2012 22:13
Example output mapping function for Presto
<?php
// NOTE that responses are automatically generated by Presto (this example simulates the call as a demonstration)
// 1. Create new Response (faking $ctx)
$r = new Response((object) array( 'res' => 'htm' ) ); // htm intentional, tests type matching
// 2. Add a new type handler, with a custom mapping (anon fn)
@tewha
tewha / gist:3065339
Created July 7, 2012 07:58 — forked from JimRoepcke/gist:3065296
@synchronized doesn't retain monitored object under MRC
__block id foo = [MyObject new];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"block entering synchronized");
@synchronized(foo) {
NSLog(@"running in synchronized");
sleep(10);
// what does @synchronized do the now-zombie foo as part of its closure?
}
NSLog(@"block exited synchronized");
});
- (void)colors {
// Working with colors in Cocoa Touch.
// I think almost everyone uses RGB decimal, which is the worst of the ways. You don't have easy control of
// brightness, and you've got decimal points in your code that don't map to the way you think of RGB.
UIColor *rgbDec = [UIColor colorWithRed:0.484 green:0.745 blue:0.191 alpha:1.000];
// If you're working from 0-255, why not just code that?
UIColor *rgbFrac = [UIColor colorWithRed:123.0/255.0 green:190.0/255.0 blue:49.0/255.0 alpha:1.000];
@tewha
tewha / keyboardWillShowNotification.m
Created September 21, 2012 00:17
keyboardWillShowNotification
- (void)keyboardWillShowNotification:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *workingView = self.view;
CGRect keyboardScreenRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect keyboardRect = [workingView convertRect:keyboardScreenRect fromView:nil];
CGRect resizeRect = [workingView convertRect:_resizingView.superview.bounds fromView:_resizingView.superview];
CGRect unionRect = CGRectIntersection(keyboardRect, resizeRect);
CGFloat bottom = resizeRect.origin.y + resizeRect.size.height;
if (!isinf(unionRect.origin.y)) {
@tewha
tewha / gist:5265978
Last active December 15, 2015 13:18
This is a category on UIImage.
- (UIImage *)rxScalePropertionallyToMaximumSize:(CGSize)maxSize blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha scale:(CGFloat)scale {
if ((maxSize.width < 1.0e-15) || (maxSize.height < 1.0e-15)) return nil;
CGSize imageSize = self.size;
CGSize scaleFactors = {
.width = maxSize.width / imageSize.width,
.height = maxSize.height / imageSize.height,
};
@tewha
tewha / DateTest.m
Last active December 24, 2015 02:39
//
// DateTest.m
// DateTest
//
// Created by Steven Fisher on 2013-09-27.
//
#import "DateTest.h"
void RunDateTest() {
@tewha
tewha / DictionaryOfEnumBindingsWorker.m
Last active December 25, 2015 08:09
Inspired by NSDictionaryOfVariableBindings.
#define DictionaryOfEnumBindings(...) DictionaryOfEnumBindingsWorker(@"" # __VA_ARGS__, __VA_ARGS__, nil)
NSDictionary *DictionaryOfEnumBindingsWorker(NSString *commaSeparatedKeysString, int firstValue, ...) {
NSMutableDictionary *enums = [NSMutableDictionary dictionary];
NSMutableArray *names = [[commaSeparatedKeysString componentsSeparatedByString:@","] mutableCopy];
va_list ap;
va_start(ap, firstValue);
NSCharacterSet *whiteSpace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString *firstPaddedName = [names objectAtIndex:0];

Keybase proof

I hereby claim:

  • I am tewha on github.
  • I am tewha (https://keybase.io/tewha) on keybase.
  • I have a public key ASAykxBa8QqrX2hg6nao3GlKI8lNUhQ4uvwPbiBrSIgNdQo

To claim this, I am signing this object:

@tewha
tewha / new-mac.md
Last active March 27, 2022 23:25
New Mac steps

This is my personal setup list. Yours may vary.

  1. Check networking.
    • May not match network you actually joined, since Apple syncs WiFi networks over iCloud account.
    • If you want to Ethernet via a Thunderbolt Display, attach the cable and restart to make the interface appear. The ones you can add are all false friends.
  2. Change Mission Control screen keyboard shortcuts for changing screens.
    • They interfere with subword navigation in Xcode.
    • These need to be changed in Keyboard Shortcuts, not Mission Control.
      • Mission Control offers fewer options.
  3. Disable caps lock.