Skip to content

Instantly share code, notes, and snippets.

View brentsimmons's full-sized avatar

Brent Simmons brentsimmons

View GitHub Profile
@brentsimmons
brentsimmons / JavaScript Indent.js
Last active April 13, 2024 11:27
This is a BBEdit text filter for indenting (and beautifying) JavaScript.
#!/usr/local/bin/node
// PBS 12/5/13
// This is a BBEdit text filter for indenting (and beautifying) JavaScript.
// It goes in ~/Library/Application Support/BBEdit/Text Filters/
//
// On my machine I assigned it a keyboard shortcut: cmd-'
//
// It requires the js-beautify Node module: https://github.com/einars/js-beautify
//
#!/usr/bin/env ruby
# PBS 4 Dec. 2013
# Renders HTML for all the .markdown files in the current directory.
# Gives each file a .html suffix.
# Saves them in a subfolder called HTML.
require 'rdiscount'
require 'find'
require 'fileutils'
@brentsimmons
brentsimmons / gist:5810992
Last active January 3, 2021 02:22
Detect a tap on a URL inside a UITextView. Note: the rs_links method isn't included -- you'll need something that takes text and returns an array of detected links. This gist just demonstrates walking through the UITextView characters.
@implementation UITextView (RSExtras)
static BOOL stringCharacterIsAllowedAsPartOfLink(NSString *s) {
/*[s length] is assumed to be 0 or 1. s may be nil.
Totally not a strict check.*/
if (s == nil || [s length] < 1)
return NO;
@brentsimmons
brentsimmons / googleSearchString.py
Created August 1, 2012 04:32
A script that generates a Google search URL and pastes it to the Mac OS X clipboard
#!/usr/bin/python
import sys
import os
from urllib import urlencode
import subprocess
# setClipboardData is from <http://www.macdrifter.com/2011/12/python-and-the-mac-clipboard/>*/
def setClipboardData(data):
@brentsimmons
brentsimmons / EmptyChecks.m
Created July 28, 2012 19:06
Checking if an object is empty
BOOL RSIsEmpty(id obj) {
return obj == nil || obj == [NSNull null] || ([obj respondsToSelector:@selector(length)] && [(NSData *)obj length] == 0) || ([obj respondsToSelector:@selector(count)] && [obj count] == 0);
}
BOOL RSStringIsEmpty(NSString *s) {
/*22 Feb. 2011: added NSNull check. JSON parser can put a null where we expect a string, and NSNull throws an exception when checking length. Since [NSNull null] is, arguably, emptiness, it makes sense to include it.*/
return s == nil || (id)s == (id)[NSNull null] || [s length] == 0;
}
@brentsimmons
brentsimmons / gist:2975795
Created June 22, 2012 23:42
Category method for UIResponder to perform a selector via responder chain
@implementation UIResponder (RSCore)
- (BOOL)rs_performSelectorViaResponderChain:(SEL)aSelector withObject:(id)anObject {
UIResponder *nomad = self;
while (nomad != nil) {
if ([nomad respondsToSelector:aSelector]) {
[nomad performSelector:aSelector withObject:anObject];
return YES;
}
nomad = [nomad nextResponder];
@brentsimmons
brentsimmons / gist:2975787
Created June 22, 2012 23:39
Local method for UIGestureRecognizer Handling
- (void)thingWasTapped:(UIGestureRecgonizer *)gestureRecognizer {
[self rs_performSelectorViaResponderChain:@selector(myRealAction:) withObject:gestureRecognizer.view];
}
@brentsimmons
brentsimmons / allstatus.rb
Created January 1, 2012 04:25
Find Mercurial repositories and print status
#!/usr/bin/env ruby -wKU
# Prints the directory names and hg status output for any Mercurial
# repositories where hg status returns something non-nil.
#
# Assumes everything is in a Projects directory in your home folder.
# 12/31/2011 Brent Simmons
require 'find'
require 'open3'