Skip to content

Instantly share code, notes, and snippets.

View acwright's full-sized avatar

Aaron Wright acwright

View GitHub Profile
@acwright
acwright / gist:b1523f804b9bd8922fbb
Last active August 29, 2015 14:17
Center view with aspect ratio
func centerViewOn(point: CGPoint) {
if let layer = self.layers.first?.layer {
let viewSize = self.view!.bounds.size
let ratioWidth = self.size.height / viewSize.height
let newWidth = viewSize.width * ratioWidth
let ratioHeight = self.size.width / viewSize.width
let newHeight = viewSize.height * ratioHeight
@acwright
acwright / gist:1163883
Created August 22, 2011 23:10
Cocoa Menu Item Title Toggle
# pragma mark menu
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
if ([menuItem action] == @selector(toggleRuler:)) {
if ([canvasView rulersVisible]) {
[menuItem setTitle:@"Hide Ruler"];
} else {
[menuItem setTitle:@"Show Ruler"];
}
}
@acwright
acwright / gist:1756744
Created February 7, 2012 02:32
Urban Finch Styling...
<p style="font-family: Bebas; font-size: 20px; color: white;">This is a headline...</p>
<p>This is some normal text on a new line... <a href="http://www.example.com">... with a link</a></p>
<p>...etc...</p>
@acwright
acwright / gist:1828870
Created February 14, 2012 18:30
API step definitions for Cucumber
Given /^I have a valid API account$/ do
@account = Account.create(:token => UUID.generate(:compact))
@token = @account.token
authorize 'x', @account.secret
end
Given /^I send and accept XML$/ do
header 'Accept', 'application/xml'
header 'Content-Type', 'application/xml'
end
@acwright
acwright / gist:1828888
Created February 14, 2012 18:32
Sinatra Cucumber setup with Capybara, RSpec and MongoMapper
ENV['RACK_ENV'] = 'test'
require File.join(File.dirname(__FILE__), '../../app.rb')
require 'capybara'
require 'capybara/dsl'
require 'rspec/expectations'
require 'rack/test'
require 'uuid'
@acwright
acwright / gist:1535473
Created December 29, 2011 18:34
Create dynamic date predicate using now() function
// The goal...
[NSPredicate predicateWithFormat:@"dateModified >= CAST(CAST(now(), \"NSNumber\") - %d, \"NSDate\")", (30*86400)];
//"now()" is a function and takes no arguments
NSExpression *now = [NSExpression expressionForFunction:@"now" arguments:[NSArray array]];
//CAST(now(), 'NSNumber')
NSArray *castNowArguments = [NSArray arrayWithObjects:now, [NSExpression expressionForConstantValue:@"NSNumber"], nil];
NSExpression *castNow = [NSExpression expressionForFunction:@"castObject:toType:" arguments:castNowArguments];
@acwright
acwright / gist:2707798
Created May 16, 2012 05:41
NSColor+Hex
#import <Cocoa/Cocoa.h>
@interface NSColor (Hex)
- (NSString *)hexadecimalValue;
+ (NSColor *)colorFromHexadecimalValue:(NSString *)hex;
@end
#import "NSColor+Hex.h"
@acwright
acwright / gist:1944639
Created February 29, 2012 21:40
Sinatra / ActionMailer / Sendgrid / Heroku
require 'sinatra'
require 'action_mailer'
class Mailer < ActionMailer::Base
def contact
mail(
:to => "test@example.com",
:from => "test@example.com",
:subject => "Test") do |format|
format.text
@acwright
acwright / fetchrequest.swift
Last active November 23, 2019 03:51
@FetchRequest
import SwiftUI
struct StudentsView: View {
@FetchRequest(
entity: Student.entity(),
sortDescriptors: [],
predicate: NSPredicate(format: "name = %@", "Joe")
) var students: FetchedResults<Student>
@acwright
acwright / fetchrequest2.swift
Created November 23, 2019 04:01
Fetch Request with dynamic predicate
import SwiftUI
struct StudentsView: View {
var request: FetchRequest<Student>
var students: FetchedResults<Student>{ request.wrappedValue }
// MARK: - Lifecycle
init(