Skip to content

Instantly share code, notes, and snippets.

View mralexgray's full-sized avatar

Alex Gray mralexgray

View GitHub Profile
@mralexgray
mralexgray / gist:5099927
Last active November 27, 2021 00:31 — forked from twobitlabs/gist:4226365
Objective-C Blocks Cheat Sheet
// http://cocoawithlove.com/2009/10/ugly-side-of-blocks-explicit.html has a nice breakdown of the syntax--it helps to think of the ^ as similar to a pointer dereference symbol *
// block typedef:
typedef void(^Block)();
typedef void(^ConditionalBlock)(BOOL);
typedef NSString*(^BlockThatReturnsString)();
typedef NSString*(^ConditionalBlockThatReturnsString)(BOOL);
// block property with typedef:
@mralexgray
mralexgray / strings `which diskutil` | grep Usage
Created June 23, 2012 19:07
OS X Lion diskutil commands (documented and hidden).sh
Usage: diskutil coreStorage list
Usage: diskutil coreStorage info[rmation] [-plist]
Usage: diskutil coreStorage convert
Usage: diskutil coreStorage revert
Usage: diskutil coreStorage create lvgName
Usage: diskutil coreStorage delete lvgUUID
Usage: diskutil coreStorage addDisk lvgUUID NewMemberDeviceName
Usage: diskutil coreStorage removeDisk pvUUID
Usage: diskutil coreStorage deleteVolume lvUUID
Usage: diskutil coreStorage resizeVolume lvUUID size
@mralexgray
mralexgray / gist:2959642
Created June 20, 2012 12:21
ipv6 tunnelbroker / he.net dyndns setup / update
echo `curl -k --trace -s https://domain.com:XXXXXXXXXXXXXXXX@dyn.dns.he.net/nic/update?hostname=domain.com`
// XXXXXXXXXXXXXXXXX = dns.he.net key
-ERROR: Missing parameter(s).
Usage: https://ipv4.tunnelbroker.net/ipv4_end.php?ip=IPV4ADDR&pass=MD5PASS&apikey=USERID&tid=TUNNELID
-or-: https://USERNAME:PASSWORD@ipv4.tunnelbroker.net/ipv4_end.php?tid=TUNNELID (auto-detect IP)
https://USERNAME:PASSWORD@ipv4.tunnelbroker.net/ipv4_end.php?tid=TUNNELID&ip=IPV4ADDR
IPV4ADDR: Your IPv4 endpoint. Set to AUTO to determine your IP based on the IP you requested this page from. Previously passed as ipv4b.
@mralexgray
mralexgray / extensionrape.md
Created May 21, 2014 09:00
Extract & Edit a Safari Extension

fromhttp://blog.jerodsanto.net/2010/08/extract-edit-a-safari-extension/

21 Aug 2010 I asked this on Twitter the other day, but alas nobody came back with an answer.

Turns out it’s pretty easy to edit a Safari extension that you’ve downloaded. The downloaded file will have a .safariextz file extension. To extract the contents of the file, use the xar command. I’ll demonstrate with the BetterSource extension.

xar -xf BetterSource-1.0.safariextz
@mralexgray
mralexgray / Brewfile
Last active April 20, 2020 04:36 — forked from codeinthehole/osx_bootstrap.sh
Script to install stuff I want on a new OSX machine
tap "caskroom/cask"
tap "denji/nginx"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-fonts"
tap "homebrew/cask-versions"
tap "homebrew/core"
tap "homebrew/dupes"
tap "homebrew/services"
tap "mongodb/brew"
@mralexgray
mralexgray / MWWebSnapshot.m
Created October 16, 2012 19:36
Create Snapshot Images from Webpages in Cocoa
// MWWebSnapshot
//
// Created by Jim McGowan on 08/09/2010.
// Copyright 2010 Jim McGowan. All rights reserved.
//
// This code is made available under the BSD license.
// Please see the accompanying license.txt file
// or view the license online at http://www.malkinware.com/developer/License.txt
//
@mralexgray
mralexgray / trumpisms.json
Last active April 18, 2020 18:13
dumb things he says
{
"style": [
"Let me tell you something, this is one of the most pathetic, stupid questions I have ever seen on Quora! Sad! I kid you not, we need to report this person to Quora moderation, and no one does that better than me, believe me.",
"I have gotten so fed up with Quora lately, I kid you not. I tell you what, I’m going to make a new site. It will be a very good site, and I will deport people like you from that site. And honestly, if you don’t like it… I’m sorry. And quite frankly, Quirky Quorans like you are just as bad as Crooked Hillary.",
"I tell you what, if we can’t make Quora great again, I will make a new site. It will be so good -and let me tell you something- people will say it is a very good site. I will have the best site, I kid you not. It will be so good.",
"And you know what? I will build a great, great firewall around this site. It will keep all the hackers out – won’t even have to deport them! I tell you what, this site will be so amazing. It will be the best site. In fact- It w
@mralexgray
mralexgray / customURL.m
Created October 19, 2012 00:33
Register Cocoa app for a custom URL scheme
Here is what you need to do to register your app for a custom URL scheme (for the example we will use a "myapp" scheme).
1) In your Info.plist, add a new entry for CFBundleURLTypes: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>MyApp's URL</string> <key>CFBundleURLSchemes</key> <array> <string>myapp</string> </array> </dict> </array>
2) Somewhere in your application's startup code (e.g. init), add this code: - (void)registerMyApp { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; }
- (void)getUrl:(NSAppleEventDescriptor )event withReplyEvent:(NSAppleEventDescriptor )replyEvent { NSString url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; // Now you can parse the URL and perform whatever action is needed }
Related Tidbits:
@mralexgray
mralexgray / gist:eac81b64f30d19ac2b0086fabe286f9b
Created November 10, 2019 00:14 — forked from howlingblast/gist:5814547
CoffeeScript: getter/setter example
Function::property = (prop, desc) ->
Object.defineProperty @prototype, prop, desc
class Person
constructor: (@firstName, @lastName) ->
@property 'fullName',
get: -> "#{@firstName} #{@lastName}"
set: (name) -> [@firstName, @lastName] = name.split ' '
p = new Person 'Leroy', 'Jenkins'
@mralexgray
mralexgray / logProperties.m
Last active September 3, 2019 09:02
A concise category on NSObject to log all declared properties, pretty-like, using minimal SLOC.
#import <objc/message.h>
#define DECORATE printf("\n\n+*%%$%%*+-+*%%$%%*+-+*%%$-+*%%$%%*+-+*%%$%%*+-+*%%$-+*%%$%%*+-+*%%$%%*+-\n\n")
@implementation NSObject (logProperties) - (void) logProperties { DECORATE; @autoreleasepool { unsigned int propCt = 0;
const char * myName = [self.description substringWithRange:
(NSRange){1,[self.description rangeOfString:@":"].location-1}].UTF8String;
objc_property_t *pA = class_copyPropertyList(self.class, &propCt);
for (int i = 0; i < propCt; i++) { NSString *name; printf("%s [%s] = %s\n", myName,
(name = [NSString.alloc initWithUTF8String:property_getName(pA[i])]).UTF8String,
[objc_msgSend(self,NSSelectorFromString(name)) description].UTF8String);
} free(pA); } DECORATE; }