Skip to content

Instantly share code, notes, and snippets.

View NoNews's full-sized avatar

Alexey Bykov NoNews

View GitHub Profile
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 { {} }
@NoNews
NoNews / Dog.java
Created January 7, 2019 17:44
Work with fragments with transfer data
public class Dog implements Serializable {
private String name;
public Dog(String name) {
this.name = name;
}
public String getName() {
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():
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())
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;
oldSize+(oldSize>>1) 
//4->8->12->18->27->...
...
index = ~index; //~-1 == 0
...
mHashes[index] = hash;
mArray[index<<1] = key; //Xor 0 == 0
mArray[(index<<1)+1] = value; //Xor 0 + 1 == 1
mSize++;
val user2 = User(id = 9986, name = "Diane Nguyen")
val key = Key(user2.name)
map[key] = user
val user3 = User(id = 2508, name = "Penny Carson") //hashCode will be 12
val key = Key(user3.name)
map[key] = user
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)