Skip to content

Instantly share code, notes, and snippets.

View wbyoung's full-sized avatar

Whitney Young wbyoung

  • FadingRed
  • Portland, OR
View GitHub Profile
@wbyoung
wbyoung / test.m
Created November 29, 2011 17:49
Macro for safely call nil block
// gcc test.m -o test -framework Foundation
#import <Foundation/Foundation.h>
#define safeblock(block) ((typeof(block))(block ? ((id)block) : ((id)^{})))
int main() {
void (^block)(NSString *) = ^(NSString *anArgument){
NSLog(@"Hello %@", anArgument);
};
safeblock(block)(@"world");
@wbyoung
wbyoung / gist:1941795
Created February 29, 2012 15:40
NSInvocation va_arg crash explanation
// clang -o test test.m -framework Foundation
#import <Foundation/Foundation.h>
@interface Forwarder : NSObject {
@package;
id destination;
}
@end
#define FRLog(format,...) \
NSLog(@"%@:%i:%s" format, \
[[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
__LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__)
@wbyoung
wbyoung / safari-7-ajax-failure
Created November 28, 2013 19:52
Safari 7.0 Intermittent Failure Ajax Settings
{
"url":"/some/url/",
"type":"POST",
"isLocal":false,
"global":true,
"processData":true,
"async":true,
"contentType":"application/x-www-form-urlencoded; charset=UTF-8",
"accepts":{
"*":"*/*",
@wbyoung
wbyoung / game-no-a.json
Created April 4, 2014 20:51
JSI game description without an "A" room
{
"rooms": [
{
"name": "Z",
"north": "D",
"east": "B",
"south": null,
"west": null
},
{
@wbyoung
wbyoung / game-reordered.json
Created April 4, 2014 20:54
JSI game description with rooms reordered
{
"rooms": [
{
"name": "C",
"north": null,
"east": null,
"south": null,
"west": "B"
},
{
@wbyoung
wbyoung / game-longname.json
Created April 4, 2014 20:58
JSI game description with longer names
{
"rooms": [
{
"name": "A",
"north": "DD",
"east": "BB",
"south": null,
"west": null
},
{
@wbyoung
wbyoung / ssh-keygen-and-pbcopy.sh
Last active August 29, 2015 13:59
Create and copy SSH key
RSA="${HOME}/.ssh/id_rsa"
PUB="${RSA}.pub"
if ! [ -f "${RSA}" ] && ! [ -f "${PUB}" ]; then
/usr/bin/ssh-keygen -q -t rsa -N "" -f "${RSA}"
fi
/bin/cat "${PUB}" | /usr/bin/pbcopy
@wbyoung
wbyoung / gulpfile.js
Last active August 29, 2015 14:00
gulpfile.js
'use strict';
var gulp = require('gulp');
var path = require('path');
var es = require('event-stream');
var $ = require('gulp-load-plugins')();
var _ = require('lodash');
var SERVER_PORT = process.env.PORT || 9000;
var LIVERELOAD_PORT = process.env.LIVERELOAD_PORT || 35729;
@wbyoung
wbyoung / promise.js
Created May 10, 2014 03:51
Bluebird 1.2.4 Node.js installation
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*