Skip to content

Instantly share code, notes, and snippets.

@odlp
odlp / environment_helper.rb
Last active October 27, 2021 16:32
Modifying the test environment temporarily
module EnvironmentHelper
def with_environment(replacement_env)
original_env = ENV.to_hash
ENV.update(replacement_env)
yield
ensure
ENV.replace(original_env)
end
end
@odlp
odlp / FirstViewController.swift
Created October 7, 2016 10:31
Segue Example Tests
import UIKit
class FirstViewController: UIViewController {
@IBOutlet weak var nextButton: UIButton!
@IBAction func didTapNextButton() {
performSegue(withIdentifier: "moveToSecondScreen", sender: nil)
}
}
@odlp
odlp / prompt_command.bash
Last active October 7, 2016 13:33
Highlight non-zero exit status for bash-it
function prompt_command() {
highlight_non_zero_exit
PS1="\n${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} "
}
function highlight_non_zero_exit() {
PASS=$?
if [[ $PASS != 0 ]]; then
printf "${echo_bold_red}> Exit status $PASS <${echo_reset_color}\n"
fi
@odlp
odlp / Name.swift
Created August 15, 2016 16:31
Swift Class name as a String
//: Playground - noun: a place where people can play
import UIKit
// Option 1 ---------------------------
protocol DescribeableClass {
static func className() -> String
}
extension DescribeableClass {
@odlp
odlp / ListDiffer.swift
Created March 28, 2016 15:27
Swift list differ for smarter UITableView refreshes
import Foundation
class ListDiffer<T: Equatable> {
private let beforeList: [T]
private let afterList: [T]
private let section: Int
private let elementComparison: ((T, T) -> Bool)
init(before: [T], after: [T], section: Int = 0, elementComparison: ((T, T) -> Bool) = { $0 == $1 }) {
@odlp
odlp / ci.sh
Last active April 29, 2016 10:53
iOS build on CI
#!/bin/sh
set -e
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Ensure Jenkins is using rbenv
export PATH=/usr/local/bin:$PATH
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
@odlp
odlp / brewstrap.rb
Created November 5, 2015 16:01
Brewstrap: Taps the taps, installs the formulae & casks
#!/usr/bin/env ruby
require 'yaml'
CONFIG_FILE_NAME = 'brewstrap.yml'
COMMAND_INSTALL_CASK = 'brew install caskroom/cask/brew-cask'
COMMAND_BREW_UPDATE = 'brew update'
COMMAND_FORMULA_INSTALL = 'brew install'
COMMAND_BREW_TAP = 'brew tap'
COMMAND_BREW_CASK_INSTALL = 'brew cask install --appdir=/Applications'
@odlp
odlp / options_request.rb
Created January 18, 2015 08:57
RSpec Options (CORS) request support
# Add support for 'options' request test. Place in /spec/support
# https://github.com/rspec/rspec-rails/issues/925#issuecomment-62527611
module ActionDispatch::Integration::RequestHelpers
def options(path, parameters = nil, headers_or_env = nil)
process :options, path, parameters, headers_or_env
end
end
@odlp
odlp / x_controller_spec.rb
Last active October 13, 2015 16:47
RSpec Controller spec request type CONTENT_TYPE
before(:each) { @request.env["CONTENT_TYPE"] = "application/json" }
@odlp
odlp / gist:19d750af7d185bb1bd74
Created August 28, 2014 14:22
ISO8601 string
def iso8601_string? datetime_str
(datetime_str =~ /\A\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)\z/) == 0
end