Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / detect-modernizr-use.rb
Created January 30, 2017 17:02
Detect modernizr - Is it being used in the project?
# Determine the feature list from the custom build URL in the source file, e.g.:
# Build: http://modernizr.com/download/#-fontface-backgroundsize-borderimage-borderradius-boxshadow-flexbox-flexboxlegacy-hsla-multiplebgs-opacity-rgba-textshadow-cssanimations-csscolumns-generatedcontent-cssgradients-cssreflections-csstransforms-csstransforms3d-csstransitions-applicationcache-canvas-canvastext-draganddrop-hashchange-history-audio-video-indexeddb-input-inputtypes-localstorage-postmessage-sessionstorage-websockets-websqldatabase-webworkers-geolocation-inlinesvg-smil-svg-svgclippaths-touch-webgl-cssclasses-teststyles-testprop-testallprops-hasevent-prefixes-domprefixes-load
has_features = [
"fontface",
"backgroundsize",
"borderimage",
"borderradius",
"boxshadow",
"flexbox",
@odlp
odlp / jasmine_seed_reporter.js
Last active March 10, 2022 20:57
Jasmine / Karma seed reporter for random test order
var SeedReporter = function(baseReporterDecorator) {
baseReporterDecorator(this);
this.onBrowserComplete = function(browser, result) {
if (result.order && result.order.random && result.order.seed) {
this.write("%s: Randomized with seed %s\n", browser, result.order.seed);
}
};
};
@odlp
odlp / .nvmrc
Last active September 25, 2017 14:48
Modern node on CircleCI
8.5
@odlp
odlp / ci_update_chrome
Last active May 23, 2018 14:31
Update Chrome on CI
#!/bin/sh
# Exit if any subcommand fails
set -e
# Install latest stable version of Chrome
curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome.deb
sudo sed -i 's|HERE/chrome\"|HERE/chrome\" --disable-setuid-sandbox|g' /opt/google/chrome/google-chrome
rm google-chrome.deb
@odlp
odlp / nof.sh
Created June 9, 2017 11:35
No focus specs
#!/bin/sh
set -eu
failIfPresentInSpecs() {
REGEX=$1
if find spec -type f -name "*_spec.rb" -exec grep -E "$REGEX" {} +; then
printf "\nFound focused specs\n"
exit 1
fi