Skip to content

Instantly share code, notes, and snippets.

Rob Mayoff mayoff

Block or report user

Report or block mayoff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mayoff / gist:1138816
Last active Jun 25, 2019
AppleScript to make Google Chrome open/reload a URL
View gist:1138816
(* 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. *)
tell application "Google Chrome"
set theUrl to ""
if (count every window) = 0 then
make new window
end if
set found to false
mayoff / gist:1185476
Created Sep 1, 2011
Emacs Lisp to reload a URL in Chrome (using AppleScript)
View gist:1185476
(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 "
mayoff / main.m
Created Apr 29, 2012
reduced fractions in objective-c
View main.m
#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;
mayoff / gist:3384659
Created Aug 18, 2012
Make objc_msgSend without a cast give a warning
View gist:3384659
#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;
mayoff / gist:3744325
Created Sep 18, 2012
Problems with NSHipster NSCharacterSet example
View gist:3744325
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]]];
mayoff / Arrow.swift
Last active Oct 29, 2019
UIBezierPath category to create an arrow (now with a Swift version!)
View Arrow.swift
// 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
mayoff / ArrowLayer.h
Created Nov 27, 2012
A CALayer subclass that draws a very simple arrow
View ArrowLayer.h
#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;
mayoff / InnerShadowView.h
Created Nov 28, 2012
UIView subclass that draws an inner shadow in a rounded rectangle
View InnerShadowView.h
// For an explanation of this code, see:
#import <UIKit/UIKit.h>
@interface InnerShadowView : UIView
@property (nonatomic, strong) UIColor *fillColor;
@property (nonatomic) CGFloat cornerRadius;
@property (nonatomic, strong) UIColor *shadowColor;
mayoff / UIBezierPath+forEachElement.h
Created Dec 2, 2012
dragging an object along a CGPath on iOS demo
View UIBezierPath+forEachElement.h
#import <UIKit/UIKit.h>
@interface UIBezierPath (forEachElement)
- (void)forEachElement:(void (^)(CGPathElement const *element))block;
mayoff / ViewController.m
Created Dec 20, 2012
Animate a CALayer's position starting from its current (possibly mid-animation) position.
View ViewController.m
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
@implementation ViewController {
CALayer *_layer;
You can’t perform that action at this time.