Skip to content

Instantly share code, notes, and snippets.

View Custom ImplicitOptionalDescription.swift
extension Optional : CustomStringConvertible {
public var description: String {
switch (self) {
case .none:
return "nil"
case let .some(value):
return "\(value)"
}
}
}
View unwrappedDescription.swift
func unwrappedDescription<T>(_ value: Optional<T>) -> String {
guard let value = value else {
return "None."
}
return "\(value)"
}
View VendingMachineTestCases.swift
//test case #1
func testVMInvalidSelection{
//Prepare
let vendingMachine = VendingMachine()
var didReceiveInvalidSelectionError = false
//Execute
do{
try vendinMachine.vend("Coke")
@bharath2020
bharath2020 / VendingMachine.swift
Last active Feb 22, 2016
VendingMachine Test Cases
View VendingMachine.swift
struct Item {
var price: Int
var count: Int
}
enum VendingMachineError: ErrorType {
case InvalidSelection
case InsufficientFunds(coinsNeeded: Int)
case OutOfStock
}
@bharath2020
bharath2020 / testPlayer1WinnerHorizontally.swift
Created Jan 24, 2016
Tic-Tac-Toe Test if there is a win for player Horizontally
View testPlayer1WinnerHorizontally.swift
func testWinnerHorizontally(){
//Prepare: Setup the board and place markers such that player wins in horizontal direction
let board = TTBoard(boardIDString: NSUUID().UUIDString)
board.markPosition(0, playerCode: 1);
board.markPosition(3, playerCode: 2);
board.markPosition(1, playerCode: 1);
board.markPosition(5, playerCode: 2);
board.markPosition(2, playerCode: 1);
@bharath2020
bharath2020 / TTBoardTests.swift
Created Dec 29, 2015
Prerparation, Execution, Verification
View TTBoardTests.swift
func testWinnerHorizontally(){
//PREPARATION
//Prepare a board and mark position so that playerCode '1' wins
let board = TTBoard(boardIDString: NSUUID().UUIDString)
board.markPosition(0, playerCode: 1)
board.markPosition(3, playerCode: 2)
board.markPosition(1, playerCode: 1)
board.markPosition(5, playerCode: 2)
board.markPosition(2, playerCode: 1)
@bharath2020
bharath2020 / TTBoard.swift
Last active Dec 29, 2015
TTBoard.swift class from Tic-Tac-Toe
View TTBoard.swift
//
// TTBoard.swift
// Tic-Tac-Toe-Swift
//
// Created by Bharath Booshan on 9/12/15.
// Copyright (c) 2015 FeatherTouch. All rights reserved.
//
import Foundation
import UIKit
View gist:9f156d8f6e6dfe719552
import java.util.ArrayList;
/**
* Created by bbooshan on 2/3/15.
*/
public class FTSynchronizedArray<T> {
private ArrayList<T> itemStore;
View Download 'data' from Android without roooting
//download data.ab (encrypted) and DONOT GIVE ANY PASSWORD when prompted
adb backup -f ~/data.ab -noapk app.package.name
//decrypt and extract the data.ab [this worked most of the time except for few instances ]
//this will output all the contents of app into 'apps' directory
dd if=data.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -
//SOURCE: http://blog.shvetsov.com/2013/02/access-android-app-data-without-root.html
@bharath2020
bharath2020 / CameraFlash-TurnOFF
Created Jan 23, 2015
Switch ON / OFF Flash in Android
View CameraFlash-TurnOFF
public void turnOFF()
{
param = cam.getParameters();
param.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.setParameters(param);
cam.stopPreview();
cam.release();
cam=null;
}