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
<?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">
- (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]);
}
#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 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 / 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 / maskCorners.swift
Created November 29, 2015 06:32
Playground for masking corners of a UIView
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 March 13, 2013 21:30
Test program that converts an arbitrary-precision decimal digit string to a hex digit string.
#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 July 12, 2013 05:05
My .lldbinit for Cocoa Coders
# 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]/'