Skip to content

Instantly share code, notes, and snippets.

View tsujeeth's full-sized avatar

Sujeeth tsujeeth

  • San Francisco, CA
View GitHub Profile
@tsujeeth
tsujeeth / connected_observable_demo.md
Last active April 26, 2017 18:41
Instead of replay, use a connectable observable
    public static void main(String[] args) {
        ConnectableObservable<String> producer = Observable.just("Hello World 100").publish();

        Observable<String> hi = producer.map(String::toUpperCase);
        Observable<String> lo = producer.map(String::toLowerCase);
        Observable<String> no100 = producer.filter(s -> s.contains("100")).map(s -> s.replace("100", "1000"));

        Observable<String> combined = Observable.merge(lo, hi, no100);
 combined.subscribe(System.out::println);

Keybase proof

I hereby claim:

  • I am tsujeeth on github.
  • I am tsujeeth (https://keybase.io/tsujeeth) on keybase.
  • I have a public key ASBeqXGSzt51yfJQwt50P72PLfLv-qFtEH6qdkLSbW7CXQo

To claim this, I am signing this object:

@tsujeeth
tsujeeth / SimpleWaitNotifyExample.java
Created June 17, 2016 01:08
Example of Wait-Notify synchronization in Java
class Bottle {
private String message;
Bottle() {
message = "";
}
public synchronized void set(String message) {
this.message = message;
notifyAll();
@tsujeeth
tsujeeth / Cluster.py
Last active March 24, 2016 04:35
Given a 2-D matrix of 0s and 1s, find the largest cluster of 1s.
#!/usr/bin/python
import random
import dfs
def add_edge(adj, u, v):
if u in adj:
current = adj[u]
adj[u] = current + [v]
else:
@tsujeeth
tsujeeth / file_update.go
Created January 7, 2016 01:12
Example of setting a watch on modifications of a given file
package main
import (
"log"
"os"
"time"
)
func getLastModTime(filename string) time.Time {
fileInfo, err := os.Stat(filename)
@tsujeeth
tsujeeth / fetch_urls_async.py
Last active August 29, 2015 14:15
Async HTTP Client, using Tornado, to fetch a list of URLs
# The list of URLs is provide in an input file.
# (assuming one URL per line)
from tornado import httpclient
from tornado import gen
from tornado.ioloop import IOLoop
class Fetcher:
def __init__(self):
self.client = httpclient.AsyncHTTPClient()
@tsujeeth
tsujeeth / get_from_map.go
Created December 5, 2014 16:51
Using Golang's reflect package (MakeFunc) to implement typed accessors for a map.
/* Using reflect.MakeFunc to fetch from map[string]interface{}.
* getString(key) will either return the 'string' value or empty string.
* getInt(key) will either return the 'int' value or a 0.
*/
package main
import (
"fmt"
"reflect"