Skip to content

Instantly share code, notes, and snippets.

public extension String {
public func localize(tableName tableName: String? = nil, bundle: NSBundle = NSBundle.mainBundle(), comment: String = "") -> String {
return NSLocalizedString(
self,
tableName: tableName,
bundle: bundle,
value: "",
comment: comment)
}
}
public class ABTester {
public init() {}
/** Randomly chooses a weighted generic item from a list of item
- item: a weighted item
- more: more weighted items as a variadic parameter
- randomNumberGenerator: random number generator
- returns: the selected generic item
- discussion:
We force the first item to be provided so we ensure that we don't end up with an empty list of items
@asalom
asalom / VersionNumber.swift
Created May 17, 2017 07:56
Compare version numbers for the format MAJOR.MINOR.REVISION in Swift
public struct VersionNumber: Equatable, Comparable {
public let version: String
public init(version: String) {
self.version = version
}
}
// Returns 1 if lhs > rhs, -1 if lhs < rhs and 0 if lhs = rhs
private func compare(_ lhs: VersionNumber, _ rhs: VersionNumber) -> Int {
rvm use ruby-2.0.0@project_name --ruby-version --create
@asalom
asalom / commit-msg
Created November 27, 2018 14:52
Prefix every commit with the JIRA ticket, given that the ticket can be found in the current branch's name
#!/bin/sh
COMMIT_FILE=$1
COMMIT_MSG=$(cat $1)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+")
if [ ! -z "$JIRA_ID" ]; then
echo "[$JIRA_ID] $COMMIT_MSG" > $COMMIT_FILE
echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)"
@asalom
asalom / tools.md
Last active April 22, 2020 14:42
Alex Salom's tools & more
  1. iTerm 2
  2. Oh My Zsh
  3. Powerline shell: path bars, edit config and remove username and hostname
  4. Meslo Powerline Font as you need a font that supports the directory characters for powerline
  5. Homebrew
  6. RVM
  7. Bundler
  8. direnv: Unclutter your .profile
  9. z: quickly jump between projects. Like Alfred but for your Terminal reduced to folder search only
  10. echo "gem: --no-document" &gt;&gt; ~/.gemrc to stop installing docs every time you install a gem