Skip to content

Instantly share code, notes, and snippets.

View rohmanhakim's full-sized avatar
😪
Back to Basic

Muhammad Arif Rohman Hakim rohmanhakim

😪
Back to Basic
View GitHub Profile
package java.util;
public interface List<E> extends Collection<E> {
boolean add(E e);
boolean remove(Object o);
E get(int index);
@rohmanhakim
rohmanhakim / Enable CORS in Spark Java
Created February 20, 2019 14:49 — forked from saeidzebardast/Enable CORS in Spark Java
Enable CORS in Spark Java to allow origins *
options("/*",
(request, response) -> {
String accessControlRequestHeaders = request
.headers("Access-Control-Request-Headers");
if (accessControlRequestHeaders != null) {
response.header("Access-Control-Allow-Headers",
accessControlRequestHeaders);
}
val observable = Observable.just("some event")
.map {
Thread.sleep(randomInt())
System.currentTimeMillis()
}
.publish()
.autoConnect(2)
val sub1 = observable.subscribe({ println("sub1 got : $it") },{})
val sub2 = observable.subscribe({ println("sub2 got : $it") },{})
val observable = Observable.just("some event")
.map {
Thread.sleep(randomInt())
System.currentTimeMillis()
}
val sub1 = observable.subscribe({ println("sub1 got : $it") },{})
val sub2 = observable.subscribe({ println("sub2 got : $it") },{})
@rohmanhakim
rohmanhakim / vim solarized in iTerm2
Created February 24, 2017 14:34 — forked from l4u/vim solarized in iTerm2
vim solarized in iTerm2
# .profile
export TERM=xterm-256color
# .vimrc
syntax on
set background = dark
let g:solarized_termcolors = 256
colorscheme solarized
Observable<Boolean> emailStream = RxTextView.textChanges(etEmail)
.map(new Func1<CharSequence, String>() {
@Override
public String call(CharSequence charSequence) {
return charSequence.toString();
}
})
.filter(new Func1<String, Boolean>() {
@Override
public Boolean call(String input) {
.debounce(100,TimeUnit.MILLISECONDS)
.map(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
// butuh fungsi yang me-return boolean
}
});
// Return true jika password yang diketik user < 6 karakter
Observable<Boolean> passwordStream = RxTextView.textChanges(etPassword)
.map(new Func1<CharSequence, Boolean>() {
@Override
public Boolean call(CharSequence charSequence) {
return !TextUtils.isEmpty(charSequence)
&& charSequence.toString().trim().length() < 6;
}
});
// Ambil daftar email dari APi, kemudian cek apakah email user sudah dipakai
public Observable<Boolean> checkIfEmailExistFromAPI(final String input){
return service.getEmails()
.flatMap(new Func1<List<String>, Observable<String>>() { // Mengubah stream of List<String> menjadi stream of String
@Override
public Observable<String> call(List<String> strings) {
return Observable.from(strings);
}
}).contains(input) // Cek apakah email di emit oleh stream sebelumnya
.subscribeOn(Schedulers.newThread())
package com.rohmanhakim.androidreactivedemo;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;