Skip to content

Instantly share code, notes, and snippets.

View collindonnell's full-sized avatar

Collin Donnell collindonnell

View GitHub Profile
@collindonnell
collindonnell / gist:1458205
Created December 11, 2011 03:58
Draw a two part gradient in a given graphics context in one line of code.
- (void)drawGradientInContext:(CGContextRef)context withStartPosition:(CGPoint)startPosition endPosition:(CGPoint)endPosition startColor:(UIColor *)startColor endColor:(UIColor *)endColor
{
CGFloat locations[2] = {0.0, 1.0};
const CGFloat *startComponents = CGColorGetComponents(startColor.CGColor);
const CGFloat *endComponents = CGColorGetComponents(endColor.CGColor);
CGFloat components[8] = {startComponents[0], startComponents[1], startComponents[2], startComponents[3], endComponents[0], endComponents[1], endComponents[2], endComponents[3]};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);
CGContextDrawLinearGradient(context, gradient, startPosition, endPosition, 0);
@collindonnell
collindonnell / ALBUpdateBundleVersion.py
Created February 20, 2012 01:47
Automated Xcode build script to update CFBundleVersion, commit and tag with Git.
#!/usr/bin python
from AppKit import NSMutableDictionary
import os
# Get the name of the current configuration.
configuration = os.environ['CONFIGURATION']
# List of valid configurations where this script should run.
configurations_list = ['Beta', 'App Store']
@collindonnell
collindonnell / BBedit-Preview-in-Marked.scpt
Created February 29, 2012 05:56
Preview BBEdit Document in Marked
-- Preview the currently active BBEdit document using Marked.
tell application "BBEdit"
activate
-- Ask BBEdit for it's active document.
set the_document to active document of text window 1
-- If the file doesn't alreay exist, ask the user to save it.
if not the_document's on disk then
save the_document
@collindonnell
collindonnell / Share With Dropbox.scpt
Created April 1, 2012 21:44
Copy's one or multiple items to the Dropbox public folder and copy's the URL's to the clipboard as a comma separated list.
(* Copyright (C) 2012 Collin Donnell
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE US
@collindonnell
collindonnell / Safari to Pinboard.applescript
Last active March 7, 2017 14:19
Send the frontmost Safari tab to Pinboard using LaunchBar. Separate tags by spaces in LaunchBar's input field.
(*
Send the URL of the Safari tab to Pinboard from LaunchBar
Author: Collin Donnell
Website: http://collindonnell.com
Date: 2013-01-06
Initially based on script for sending Chrome links to Pinboard
using Alfred by Tim Bueno:
http://www.timbueno.com/2012/06/27/pinboard-plus-alfred
@collindonnell
collindonnell / Octopress New Post.applescript
Last active December 10, 2015 18:09
Create a new Octopress post from LaunchBar.
(*
Create a new post in Octopress from Launchbar
Author: Collin Donnell
Website: http://collindonnell.com
Date: 01/06/2013
*)
on handle_string(postTitle)
try
@collindonnell
collindonnell / Octopress Publish.applescript
Created January 8, 2013 02:28
Generate and deploy Octopress blog from LaunchBar or other script launcher.
(*
Generate and deploy Octopress site from Launchbar
Author: Collin Donnell
Website: http://collindonnell.com
Date: 01/07/2013
*)
-- Set to the location on disk of your site
set octopressLocation to ((path to home folder as text) & "Code:blog:") as alias
@collindonnell
collindonnell / SafelyMessageTarget.m
Last active August 29, 2015 14:03
Notify a target with the specified arguments only if it responds to a selector.
- (void)safelyMessageTarget:(id)target withSelector:(SEL)selector arguments:(NSArray *)arguments {
if ([target respondsToSelector:selector]) {
NSMethodSignature *methodSignature = [NSMethodSignature methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[arguments enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[invocation setArgument:(__bridge void *)(obj) atIndex:idx];
}];
[invocation invokeWithTarget:target];
@collindonnell
collindonnell / DeleteManagedObjectsExtension.swift
Last active December 4, 2020 23:38
NSManagedObjectContext extension methods to delete all managed objects, or all objects of a given type in the context.
//
// Created by Collin Donnell on 7/22/15.
// Copyright (c) 2015 Collin Donnell. All rights reserved.
//
import CoreData
extension NSManagedObjectContext {
convenience init(parentContext parent: NSManagedObjectContext, concurrencyType: NSManagedObjectContextConcurrencyType) {
@collindonnell
collindonnell / DeselectCurrentRowAnimated.swift
Last active August 29, 2015 14:25
UITableView Extension to Deselect Currently Selected Row
import UIKit
public extension UITableView {
public func deselectSelectedRowAnimated(animated: Bool) {
if let indexPath = indexPathForSelectedRow() {
deselectRowAtIndexPath(indexPath, animated: animated)
}
}