Skip to content

Instantly share code, notes, and snippets.

View nbomberger's full-sized avatar

Nathaniel Bomberger nbomberger

View GitHub Profile
import bisect
class NFA(object):
EPSILON = object()
ANY = object()
def __init__(self, start_state):
self.transitions = {}
self.final_states = set()
self._start_state = start_state
@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 / categorization_spec.rb
Last active August 29, 2015 13:56
Simple example of shared_examples in Rspec. Put the _shared in your support folder. Example creates a context where you have access to a logged in user.
# encoding: UTF-8
require 'spec_helper'
describe 'Category JSON Spec', focus: :true do
include_examples 'a logged in user'
describe 'Someaction#index' do
before(:each) { FactoryGirl.create_list(:category, 5) }
subject(:response) do
# you have access to the @user var
@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