Skip to content

Instantly share code, notes, and snippets.

@bharath2020
bharath2020 / 0_reuse_code.js
Created January 24, 2014 00:00
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@bharath2020
bharath2020 / gist:7287ffe7a0a1225a316d
Created August 8, 2014 23:06
HTTPUrlConnection redirect once
urlConnection = (HttpURLConnection) imageURL.openConnection();
String location = urlConnection.getHeaderField("Location");
if (location != null )
{
URL newURL = new URL(location);
urlConnection = (HttpURLConnection) newURL.openConnection();
}
//use the urlConnection now
@bharath2020
bharath2020 / CameraFlash-TurnOFF
Created January 23, 2015 19:11
Switch ON / OFF Flash in Android
public void turnOFF()
{
param = cam.getParameters();
param.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.setParameters(param);
cam.stopPreview();
cam.release();
cam=null;
}
@bharath2020
bharath2020 / Download 'data' from Android without roooting
Last active January 25, 2024 21:13
Download manifest from Android APK
//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 / gist:9f156d8f6e6dfe719552
Created February 4, 2015 21:01
Synchronized array in JAVA
import java.util.ArrayList;
/**
* Created by bbooshan on 2/3/15.
*/
public class FTSynchronizedArray<T> {
private ArrayList<T> itemStore;
@bharath2020
bharath2020 / TTBoard.swift
Last active December 29, 2015 10:52
TTBoard.swift class from Tic-Tac-Toe
//
// 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
@bharath2020
bharath2020 / TTBoardTests.swift
Created December 29, 2015 14:33
Prerparation, Execution, Verification
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 / testPlayer1WinnerHorizontally.swift
Created January 24, 2016 02:21
Tic-Tac-Toe Test if there is a win for player Horizontally
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 / VendingMachine.swift
Last active February 22, 2016 03:07
VendingMachine Test Cases
struct Item {
var price: Int
var count: Int
}
enum VendingMachineError: ErrorType {
case InvalidSelection
case InsufficientFunds(coinsNeeded: Int)
case OutOfStock
}
//test case #1
func testVMInvalidSelection{
//Prepare
let vendingMachine = VendingMachine()
var didReceiveInvalidSelectionError = false
//Execute
do{
try vendinMachine.vend("Coke")