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
abstract class BaseViewModel : ViewModel() { | |
protected val defaultErrorHandler: (Throwable) -> Unit by lazy { | |
{ throwable: Throwable -> | |
Log.e(javaClass.simpleName, "DefaultErrorHandler", throwable) | |
Unit | |
} | |
} | |
private val defaultCompleteHandler: () -> Unit by lazy { {} } |
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
public class Dog implements Serializable { | |
private String name; | |
public Dog(String name) { | |
this.name = name; | |
} | |
public String getName() { |
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 argparse | |
import os | |
parser = argparse.ArgumentParser("") | |
parser.add_argument('--target-branch', required=True) | |
args = parser.parse_args() | |
command = "git diff {target_branch} --name-status".format(target_branch=args.target_branch) | |
diffs = os.popen(command).read() | |
for current_file in diffs.splitlines(): |
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
Observable.just("Hey") | |
.subscribeOn(Schedulers.io()) | |
.map(String::length) | |
.subscribeOn(Schedulers.computation()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.doOnSubscribe { doAction() } | |
.flatMap { | |
doAction() | |
Observable.timer(1, TimeUnit.SECONDS) | |
.subscribeOn(Schedulers.single()) |
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
int indexOf(Object key, int hash) { | |
... | |
//next available position for our element = 0 | |
//to show, that we don't have this key, will execute ~0, which is equal -1 | |
int index = binarySearchHashes(mHashes, N, hash); | |
if (index < 0) { | |
// hash code not found, "put" operation | |
return index; |
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
oldSize+(oldSize>>1) | |
//4->8->12->18->27->... |
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
... | |
index = ~index; //~-1 == 0 | |
... | |
mHashes[index] = hash; | |
mArray[index<<1] = key; //Xor 0 == 0 | |
mArray[(index<<1)+1] = value; //Xor 0 + 1 == 1 | |
mSize++; |
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
val user2 = User(id = 9986, name = "Diane Nguyen") | |
val key = Key(user2.name) | |
map[key] = user |
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
val user3 = User(id = 2508, name = "Penny Carson") //hashCode will be 12 | |
val key = Key(user3.name) | |
map[key] = user |
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
data class User(val id: Int, val name: String) | |
data class Key(val name: String) { | |
//bad hashCode, for demonstration | |
override fun hashCode() = name.length | |
} | |
val map = ArrayMap<Key, User>() | |
val user = User(1507, "Bojack Horseman") | |
val key = Key(user.name) |
NewerOlder