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
View Main.storyboard
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" sceneMemberID="viewController">
View layoutSubviews.m
- (void)layoutSubviews {
[super layoutSubviews];
void objc_msgSend();
NSLog(@"%@", ((id(*)(id,SEL))objc_msgSend)(self, @selector(recursiveDescription)));
NSLog(@"hcons: %@", [self constraintsAffectingLayoutForAxis:UILayoutConstraintAxisHorizontal]);
NSLog(@"vcons: %@", [self constraintsAffectingLayoutForAxis:UILayoutConstraintAxisVertical]);
}
View longLongValueTest.m
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSMutableArray *myNums = [NSMutableArray array];
NSString *inputs = @"392 392 339 394 393 394 339";
for (NSString *word in [inputs componentsSeparatedByString:@" "]) {
NSNumber *n = [NSDecimalNumber decimalNumberWithString:word];
[myNums addObject:n];
@mayoff
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
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
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
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
mayoff / maskCorners.swift
Created Nov 29, 2015
Playground for masking corners of a UIView
View maskCorners.swift
import XCPlayground
import Foundation
import UIKit
func maskCorners(corners: [UIViewContentMode], ofView view: UIView, toDepth depth: CGFloat) {
let s = 1 + 2 * depth
let path = UIBezierPath()
if corners.contains(.TopLeft) {
path.moveToPoint(CGPoint(x: 0, y: 0 + depth))
@mayoff
mayoff / longDecimalToHex.mm
Created Mar 13, 2013
Test program that converts an arbitrary-precision decimal digit string to a hex digit string.
View longDecimalToHex.mm
#import <Foundation/Foundation.h>
#import <vector>
// index 0 is the least significant digit
typedef std::vector<uint16_t> BigInt;
static void insertDecimalDigit(BigInt &b, uint16_t decimalDigit) {
uint32_t carry = decimalDigit;
for (size_t i = 0; i < b.size(); ++i) {
uint32_t product = b[i] * (uint32_t)10 + carry;
@mayoff
mayoff / .lldbinit
Created Jul 12, 2013
My .lldbinit for Cocoa Coders
View .lldbinit
# command alias rd expression -o -- [[UIApp keyWindow] recursiveDescription]
command regex rd 's/^[[:space:]]*$/po [[UIApp keyWindow] recursiveDescription]/' 's/^(.+)$/po [%1 recursiveDescription]/'
command regex rsd 's/.*/po [UIApp Rob_recursiveSceneDescription]/'
command script import ~/.../lldb/sniff_objc_exception_throw.py
command regex hcons 's/^(.+)$/po [(id)%1 constraintsAffectingLayoutForAxis:0]/'
command regex vcons 's/^(.+)$/po [(id)%1 constraintsAffectingLayoutForAxis:1]/'
You can’t perform that action at this time.