Skip to content

Instantly share code, notes, and snippets.

Brent Simmons brentsimmons

Block or report user

Report or block brentsimmons

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
@brentsimmons
brentsimmons / JavaScript Indent.js
Last active May 16, 2020
This is a BBEdit text filter for indenting (and beautifying) JavaScript.
View JavaScript Indent.js
#!/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
//
View generate_html.rb
#!/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 Dec 20, 2018
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.
View gist:5810992
@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 Aug 1, 2012
A script that generates a Google search URL and pastes it to the Mac OS X clipboard
View googleSearchString.py
#!/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 Jul 28, 2012
Checking if an object is empty
View EmptyChecks.m
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 Jun 22, 2012
Category method for UIResponder to perform a selector via responder chain
View gist:2975795
@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 Jun 22, 2012
Local method for UIGestureRecognizer Handling
View gist:2975787
- (void)thingWasTapped:(UIGestureRecgonizer *)gestureRecognizer {
[self rs_performSelectorViaResponderChain:@selector(myRealAction:) withObject:gestureRecognizer.view];
}
@brentsimmons
brentsimmons / allstatus.rb
Created Jan 1, 2012
Find Mercurial repositories and print status
View allstatus.rb
#!/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'
You can’t perform that action at this time.