Skip to content

Instantly share code, notes, and snippets.

View mayoff's full-sized avatar
😷
status messages are fun

Rob Mayoff mayoff

😷
status messages are fun
View GitHub Profile
@mayoff
mayoff / gist:1138816
Last active December 8, 2023 22:00
AppleScript to make Google Chrome open/reload a URL
(* 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
@mayoff
mayoff / gist:1185476
Created September 1, 2011 04:49
Emacs Lisp to reload a URL in Chrome (using AppleScript)
(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
mayoff / main.m
Created April 29, 2012 20:12
reduced fractions in objective-c
#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
mayoff / gist:3384659
Created August 18, 2012 05:24
Make objc_msgSend without a cast give a warning
#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
mayoff / gist:3744325
Created September 18, 2012 17:05
Problems with NSHipster NSCharacterSet example
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
mayoff / Arrow.swift
Last active May 13, 2022 07:30
UIBezierPath category to create an arrow (now with a Swift version!)
// 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
mayoff / ArrowLayer.h
Created November 27, 2012 06:44
A CALayer subclass that draws a very simple arrow
#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
mayoff / InnerShadowView.h
Created November 28, 2012 04:25
UIView subclass that draws an inner shadow in a rounded rectangle
// 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;
@mayoff
mayoff / UIBezierPath+forEachElement.h
Created December 2, 2012 06:51
dragging an object along a CGPath on iOS demo
#import <UIKit/UIKit.h>
@interface UIBezierPath (forEachElement)
- (void)forEachElement:(void (^)(CGPathElement const *element))block;
@end
@mayoff
mayoff / ViewController.m
Created December 20, 2012 04:49
Animate a CALayer's position starting from its current (possibly mid-animation) position.
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
@end
@implementation ViewController {
CALayer *_layer;
}