This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function sync { | |
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || | |
branch_name="(unnamed branch)" # detached HEAD | |
branch_name=${branch_name##refs/heads/} | |
echo -e "\033[0;32mSyncing branch $1 into branch $branch_name...\033[0m" | |
echo -e "$(git checkout $1 && git pull)" | |
echo -e "$(git checkout $branch_name && git merge $1)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol CollectionViewType { | |
func register<T: UICollectionViewCell>(_ cellClass: T.Type) | |
func dequeue<T: UICollectionViewCell>(_ cellClass: T.Type, for indexPath: IndexPath) -> T? | |
} | |
extension UICollectionView: CollectionViewType { | |
func register<T: UICollectionViewCell>(_ cellClass: T.Type) { | |
register(cellClass, forCellWithReuseIdentifier: String(describing: cellClass)) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Comparable { | |
/// Returns a Boolean value indicating whether a value is included in a | |
/// range. | |
/// | |
/// You can use this pattern matching operator (`~=`) to test whether a value | |
/// is included in a range. The following example uses the `~=` operator to | |
/// test whether an integer is included in a range of single-digit numbers. | |
/// | |
/// let chosenNumber = 3 | |
/// if chosenNumber ~= 0...9 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Returns a Boolean value indicating whether the given element is contained | |
/// within the range. | |
/// | |
/// A `ClosedRange` instance contains both its lower and upper bound. | |
/// `element` is contained in the range if it is between the two bounds or | |
/// equal to either bound. | |
/// | |
/// - Parameter element: The element to check for containment. | |
/// - Returns: `true` if `element` is contained in the range; otherwise, | |
/// `false`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Returns a Boolean value indicating whether a value is included in a | |
/// range. | |
/// | |
/// You can use this pattern matching operator (`~=`) to test whether a value | |
/// is included in a range. The following example uses the `~=` operator to | |
/// test whether an integer is included in a range of single-digit numbers. | |
public static func ~=(pattern: ClosedRange<Bound>, value: Bound) -> Bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Section: Int { | |
case robots = 0 | |
case cats | |
case dogs | |
case humans | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
switch Section(rawValue: section) { | |
case .robots?: // return rows count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class ObservableModel: NSObject { | |
private var observers: [(keypath: String, block: (Any?) -> Void)] = [] | |
// keypath has to exist and has to have dynamic property to be notified | |
func observe<T>(keypath: String, with block: @escaping (T?) -> Void) { | |
guard let _ = value(forKeyPath: keypath) as? T else { | |
fatalError("value at \(keypath) is not of type \(T.self)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// maybe someone will find this useful | |
// i was going through codewars and | |
// encountered linkedlist challenge | |
// i noticed special A -> B operator | |
// and i decided to recreate it it swift :) | |
//MARK: custom class that holds data | |
class Node<T> { | |
var data: T | |
var next: Node<T>? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
robot.ahead(100); |