Skip to content

Instantly share code, notes, and snippets.

@bulwinkel
bulwinkel / SerializedProperty.java
Created July 31, 2016 23:44
Serialize Properties into Bundles and back (Experimental)
import android.os.Bundle;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi;
import java.io.IOException;
/**
* Removes some of the boilerplate associated with Properties in android fragments by handling
* the serialization and deserialization of wrapped objects into and out of argument
* {@link Bundle}s.
*
@bulwinkel
bulwinkel / PicassoImageObservable.kt
Created July 13, 2016 04:43
Generates Bitmap Observables with Picasso instance
class PicassoImageObservable(
private val picasso: Picasso
) : Func1<String, Observable<Bitmap>> {
override fun call(url: String): Observable<Bitmap> {
return Observable.fromAsync({ emitter ->
val target = object : Target {
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
//do nothing
}
@bulwinkel
bulwinkel / SequenceDiff.swift
Last active June 23, 2016 01:43
Run diff on 2 sequences
extension SequenceType where Self.Generator.Element : Equatable {
typealias Diff = (added: [Self.Generator.Element], removed: [Self.Generator.Element])
func diff(changed:[Self.Generator.Element]) -> Diff {
let added:[Self.Generator.Element] = changed.reduce([]) {
!self.contains($1) ? $0 + [$1] : $0
}
let removed:[Self.Generator.Element] = self.reduce([]) {