This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* To the extent possible under law, Rob Mayoff has waived all copyright and related or neighboring rights to “AppleScript to make Google Chrome open/reload a URL”. This work is published from: United States. https://creativecommons.org/publicdomain/zero/1.0/ *) | |
tell application "Google Chrome" | |
activate | |
set theUrl to "http://tycho.usno.navy.mil/cgi-bin/timer.pl" | |
if (count every window) = 0 then | |
make new window | |
end if | |
set found to false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun mayoff:open-url-in-chrome (url) | |
"Open URL in Google Chrome. I use AppleScript to do several things: | |
1. I tell Chrome to come to the front. If Chrome wasn't launched, this will also launch it. | |
2. If Chrome has no windows open, I tell it to create one. | |
3. If Chrome has a tab showing URL, I tell it to reload the tab, make that tab the active tab in its window, and bring its window to the front. | |
4. If Chrome has no tab showing URL, I tell Chrome to make a new tab (in the front window) showing URL." | |
(when (symbolp url) | |
; User passed a symbol instead of a string. Use the symbol name. | |
(setq url (symbol-name url))) | |
(do-applescript (format " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int gcd(int a, int b) { | |
// assumes a >= 0 && b > 0 | |
while (b != 0) { | |
int t = a % b; | |
a = b; | |
b = t; | |
} | |
return a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define objc_msgSend(...) (objc_msgSend_without_cast())(__VA_ARGS__) | |
static inline id (*objc_msgSend_without_cast(void))(id, SEL, ...) __attribute__((deprecated("objc_msgSend must be cast to the correct type"))); | |
static inline id (*objc_msgSend_without_cast(void))(id, SEL, ...) { | |
return objc_msgSend; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Errors in the squashing whitespace example code: | |
main.m:13:57: error: expected ';' at end of declaration | |
NSString *string = @"Lorem ipsum dolar sit amet ." | |
^ | |
main.m:14:90: error: extraneous ']' before ';' | |
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]]; | |
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift 2.2 syntax / API | |
import UIKit | |
extension UIBezierPath { | |
class func arrow(from start: CGPoint, to end: CGPoint, tailWidth: CGFloat, headWidth: CGFloat, headLength: CGFloat) -> Self { | |
let length = hypot(end.x - start.x, end.y - start.y) | |
let tailLength = length - headLength |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <QuartzCore/QuartzCore.h> | |
@interface ArrowLayer : CALayer | |
@property (nonatomic) CGFloat thickness; | |
@property (nonatomic) CGFloat startRadians; | |
@property (nonatomic) CGFloat lengthRadians; | |
@property (nonatomic) CGFloat headLengthRadians; | |
@property (nonatomic, strong) UIColor *fillColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For an explanation of this code, see: | |
// http://stackoverflow.com/questions/13595284/cgcontextcliptomask-not-clipping | |
#import <UIKit/UIKit.h> | |
@interface InnerShadowView : UIView | |
@property (nonatomic, strong) UIColor *fillColor; | |
@property (nonatomic) CGFloat cornerRadius; | |
@property (nonatomic, strong) UIColor *shadowColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIBezierPath (forEachElement) | |
- (void)forEachElement:(void (^)(CGPathElement const *element))block; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
#import <QuartzCore/QuartzCore.h> | |
@interface ViewController () | |
@end | |
@implementation ViewController { | |
CALayer *_layer; | |
} |
OlderNewer