Skip to content

Instantly share code, notes, and snippets.

View evadne's full-sized avatar
🎣
gone fishing

Evadne Wu evadne

🎣
gone fishing
View GitHub Profile
/* (CGRect) */ function CGRectInsetFromEdges (aRect, offsetTop, offsetRight, offsetBottom, offsetLeft) {
return CGRectMake(
aRect.origin.x - offsetLeft,
aRect.origin.y - offsetBottom,
aRect.size.width + offsetLeft + offsetRight,
aRect.size.height + offsetBotttom + offsetTop,
);
-- In Mail, create a new rule, then add “Run AppleScript” to the list of actions to perform. Notice that the buddy name and the service index are both hard-coded.
using terms from application "Mail"
on perform mail action with messages newMessages for rule theRule
repeat with newMessage in newMessages
set senderName to (extract name from sender of newMessage)
set subjectText to (subject of newMessage)
set contentText to (content of newMessage)
if (Number.prototype.toRad === undefined)
Number.prototype.toRad = /* (Number) */ function () { return this * Math.PI / 180; }
function MKGeographicalDistanceBetweenCoordinates (fromCoords, toCoords) {
if (CLLocationCoordinate2DEqualToCLLocationCoordinate2D(fromCoords, toCoords))
return 0;
// Vincenty Inverse Solution.
// Google Maps API v3 does not provide distance calculation, so we have to roll our own.
SET @oldsite='http://monoceroi.com', @newsite='http://iridia.tw';
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, @oldsite, @newsite);
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite);
- (void) handleKeyboardNotification:(NSNotification *)inNotification {
if (!self.contentView)
return;
CGRect (^rectFromScreenRect) (CGRect inRect) = ^ (CGRect inRect) { return [self.view convertRect:[self.view.window convertRect:inRect fromWindow:nil] fromView:nil]; };
id (^notificationObject) (id inKey) = ^ (id inKey) { return [inNotification.userInfo objectForKey:inKey]; };
CGRect (^rectFromValue) (id inValueObject) = ^ (id inValueObject) { return [((NSValue *)inValueObject) CGRectValue]; };
@evadne
evadne / gist:781857
Created January 16, 2011 14:59
Inspecting an existing Core Data store with F-Script
basePathString := '/Volumes/Data/Library/Application Support/iPhone Simulator/4.2/Applications/D1AB6AEB-6123-447B-A55F-A14603BA22FF/'
modelName := 'MLTwitterModel.momd'
storeName := 'twitter.evadne.sqlite'
modelURL := (NSURL fileURLWithPath:((basePathString stringByAppendingString:'Milk.app/') stringByAppendingString:modelName))
storeURL := (NSURL fileURLWithPath:((basePathString stringByAppendingString:'Documents/') stringByAppendingString:storeName))
coordinator := NSPersistentStoreCoordinator alloc initWithManagedObjectModel:((NSManagedObjectModel alloc initWithContentsOfURL:modelURL) autorelease)
coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:nil
@evadne
evadne / irDump.h
Created January 26, 2011 12:07
Dumping a CG struct.
#include <CoreGraphics/CGBase.h>
#define irDump(aCGStruct) NSLog(@"%@", irDumpImpl(@encode(__typeof__(aCGStruct)), &aCGStruct))
#define irDumpLog(aCGStruct,...) NSLog(@"%@: %@", irDumpImpl(@encode(__typeof__(aCGStruct)), &aCGStruct), [NSString stringWithFormat:__VA_ARGS__])
CG_INLINE NSString* irDumpImpl (const char *encodedString, void * aPointer) {
if (strcmp(encodedString, @encode(CGRect)) == 0)
return NSStringFromCGRect(*(CGRect*)aPointer);
//
// IRManagedObject.h
// Milk
//
// Created by Evadne Wu on 1/11/11.
// Copyright 2011 Iridia Productions. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "IRFoundationAdditions.h"
@evadne
evadne / uiwebview_fullscreen_media_playback_with_autororation_workaround.m
Created February 22, 2011 14:31
UIWebView Full-Screen Movie Post-Autorotation-Dismissal Layout Fix
@implementation IRWebViewController (irFullscreenMediaPlaybackAutorotationLayoutFix)
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// There is a bug, where launching a media player from the web view, fullscreening it, then rotating the device, and tapping on the media to see the timelime, causes the layout to go all berserk. This is a hack to combat that.
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
if ((!self.view.superview) || (self.parentViewController.modalViewController != self) || (self.modalPresentationStyle != UIModalPresentationFullScreen)) {
@evadne
evadne / gist:867189
Created March 12, 2011 10:57
Reduced code from a custom CPTableView controlling CPViewController
@implementation IRSampleTableViewController : MPCompanionedViewController
// Assume that you work within -loadView, and assume arrayController is an CPArrayController somewhere
- (int) numberOfRowsInTableView:(CPTableView)inTableView {
return [[arrayController contentArray] count] || 0;
}