Skip to content

Instantly share code, notes, and snippets.

View hashbrown's full-sized avatar

Brad Armstrong hashbrown

  • Code 42 Software
  • Minneapolis, MN USA
View GitHub Profile
@hashbrown
hashbrown / RXAuthenticator.java
Last active October 18, 2015 00:26
Caching and invalidating replayable observables
Stack<AuthenticationRequestHolder> cachedRequest = new Stack<>();
public Observable<AuthenticationResult> login(final AuthenticationRequest request) {
AuthenticationRequestHolder cached = cachedRequest.isEmpty()?null:cachedRequest.pop();
if (cached != null && cached.request.equals(request)) {
cachedRequest.push(cached);
return cached.result;
}
@hashbrown
hashbrown / latency.markdown
Created June 1, 2012 14:28 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
Read 1 MB sequentially from memory ..... 250,000 ns  = 250 µs

Round trip within same datacenter ...... 500,000 ns = 0.5 ms

@hashbrown
hashbrown / button_bar_layout.xml
Created April 10, 2012 13:40 — forked from romannurik/button_bar_layout.xml
How to make a proper button bar on ICS
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle">
<TextView android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"