Skip to content

Instantly share code, notes, and snippets.

View baldraider's full-sized avatar
🎯
Focusing

Sushant Kumar baldraider

🎯
Focusing
  • India
View GitHub Profile
public static String getDate(String time) {
DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
Date date = utcFormat.parse(time);
long timeDiff = System.currentTimeMillis() - date.getTime();
if (timeDiff < 86400000) {
if (timeDiff < 60) {
return "Just now";
//In this example the value 'a' is written to the console:
fun BehaviorSubjectExample(){
//Need to provide a default value.
var subject = new BehaviorSubject<string>("a")
subject.Subscribe(println(it))
}
//In this example the value 'b' is written to the console, but not 'a'.
fun BehaviorSubjectExample2(){
var subject = new BehaviorSubject<string>("a")
//In this example no values will be published as the sequence never completes. No values will be written to the console.
fun asyncSubjectExample1(){
var subject = new AsyncSubject<string>()
subject.onNext("a")
subject.onNext("b")
subject.onNext("c")
subject.subscribe(println(it))
}
//In this example we invoke the OnCompleted method so the last value 'c' is written to the console:
@baldraider
baldraider / RelaySubjectExampleBuffer.kt
Last active March 24, 2019 18:15
Relay Subject Example with buffer size
class RelaySubjectExampleBuffer {
fun main(args : Array<String>){
val bufferSize = 2
val subject = RelaySubject<String>(bufferSize)
val myObserver = MyObserver()
subject.onNext("a")
subject.onNext("b")
subject.onNext("c")
subject.subscribe(myObserver)
subject.onNext("d")
@baldraider
baldraider / RelaySubjectExample1.kt
Last active March 24, 2019 17:56
Relay Subject Example
class RelaySubjectExample1 {
fun main(args : Array<String>){
val subject = RelaySubject<String>()
val myObserver = MyObserver()
subject.onNext("a")
subject.subscribe(myObserver)
subject.onNext("b")
subject.onNext("c")
subject.onComplete()
}
@baldraider
baldraider / RxSubjectExample2.kt
Last active March 24, 2019 17:49
Subject example with late subscription
class RxSubjectExample2 {
fun main(args : Array<String>){
val subject = Subject<String>()
val myObserver = MyObserver()
subject.onNext("a")
subject.subscribe(myObserver)
subject.onNext("b")
subject.onNext("c")
subject.onComplete()
@baldraider
baldraider / RxSubjectExample.kt
Last active March 24, 2019 17:44
Standard Subject Example
class RxSubjectExample {
fun main(args : Array<String>){
val subject = Subject<String>()
val myObserver = MyObserver()
subject.subscribe(myObserver)
subject.onNext("a")
subject.onNext("b")
subject.onNext("c")
subject.onComplete()
@baldraider
baldraider / rxexample1.kt
Last active March 24, 2019 16:59
Implementing Observer<T> and Observable<T>
class ObservableObserverExample {
fun main(args : Array<String>){
val myObserver = MyObserver()
val myObservable = MyObservable()
myObservable.subscribe(myObserver)
}
class MyObserver : Observer<String>{
override fun onComplete() {
{
"org.moire.opensudoku.gui.inputmethod.IMControlPanel$1":{
"onCellTapped":{
"action": "LOG"
}
},
"org.moire.opensudoku.gui.inputmethod.IMControlPanel":{
"easterEgg":{
"action": "TRY_CATCH"
}