Skip to content

Instantly share code, notes, and snippets.

View nbomberger's full-sized avatar

Nathaniel Bomberger nbomberger

View GitHub Profile
@nbomberger
nbomberger / file.swift
Last active August 29, 2015 14:09 — forked from frozzare/file.swift
import Foundation
class File {
class func exists (path: String) -> Bool {
return NSFileManager().fileExistsAtPath(path)
}
class func read (path: String, encoding: NSStringEncoding = NSUTF8StringEncoding) -> String? {
if File.exists(path) {
@nbomberger
nbomberger / Podfile-snippet
Last active August 29, 2015 14:07 — forked from funroll/Podfile-snippet
This is an improved version that combines the above two versions and works for Xcode 5.1.1. Based on the (updated) original by Cameron Spickert.
# Remove 64-bit build architecture from all pod targets and override 'Build Active Architecture Only' to NO.
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |configuration|
target.build_settings(configuration.name)['VALID_ARCHS'] = '$(ARCHS_STANDARD_32_BIT)'
target.build_settings(configuration.name)['ONLY_ACTIVE_ARCH'] = 'NO'
end
end
end
@interface NSFileManager (DoNotBackup)
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;
@end
/*
File: KeychainItemWrapper.h
Abstract:
Objective-C wrapper for accessing a single keychain item.
Version: 1.2 - ARCified
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
# inspired by https://gist.github.com/406460 and
# http://pivotallabs.com/users/rolson/blog/articles/1249-stubbing-out-paperclip-imagemagick-in-tests
# plus some additional monkeypatching to prevent "too many files open" err's
#
# place this file in <app root>/spec/support
#
RSpec.configure do |config|
$paperclip_stub_size = "800x800"
end
# RSpec's subject method, both implicitly and explicitly set, is useful for
# declaratively setting up the context of the object under test. If you provide a
# class for your describe block, subject will implicitly be set to a new instance
# of this class (with no arguments passed to the constructor). If you want
# something more complex done, such as setting arguments, you can use the
# explicit subject setter, which takes a block.
describe Person do
context "born 19 years ago" do
subject { Person.new(:birthdate => 19.years.ago }
it { should be_eligible_to_vote }
# config/initializer/notification_center.rb
NotificationCenter.queue
NotificationCenter.thread
ActiveSupport::Notifications.subscribe /(.)+\.notification/i do |*args|
NotificationCenter.queue << args
end
@nbomberger
nbomberger / hash.rb
Created February 16, 2014 04:56 — forked from rmw/hash.rb
class Hash
def with_sym_keys
self.inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo }
end
end
@nbomberger
nbomberger / hash.rb
Created February 15, 2014 20:40 — forked from rmw/hash.rb
class Hash
# options:
# :exclude => [keys] - keys need to be symbols
def to_ostruct_recursive(options = {})
convert_to_ostruct_recursive(self, options)
end
private
def convert_to_ostruct_recursive(obj, options)
result = obj
class SpecialResponderController < ActionController::Base
protected
def self.responder
lambda do |controller, resources, options|
if controller.is_special?
SpecialResponder.call(controller, resources, options)
else
super.call(controller, resources, options)
end
end