Skip to content

Instantly share code, notes, and snippets.

@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([]) {
@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 / 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 / Windows.java
Created August 18, 2016 13:08
Android Window Utilities
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.view.Window;
import android.view.WindowManager;
public class Windows {
private Windows() {
//no instances
@bulwinkel
bulwinkel / TypedValues.java
Created August 18, 2016 13:11
Android TypedValue Utilities (px -> dp)
import android.content.Context;
import android.util.TypedValue;
public class TypedValues {
private TypedValues() {
//no instances
}
public static int dip(Context context, float dp) {
@bulwinkel
bulwinkel / CharSequences.java
Created January 12, 2017 01:40
Android helper functions for highlighting a search term in a given CharSequence.
import android.support.annotation.ColorInt;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jetbrains.annotations.NotNull;
import static android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonReader;
import com.squareup.moshi.JsonWriter;
import com.squareup.moshi.Moshi;
import com.squareup.moshi.Types;
import io.realm.RealmList;
import io.realm.RealmModel;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
@bulwinkel
bulwinkel / HttpExceptions.java
Last active July 4, 2017 07:51
Utility class for checking if a Throwableis a HttpException of a specific codes.
package com.nm.support.okhttp;
import retrofit2.HttpException;
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
public final class HttpExceptions {
private HttpExceptions() {
@bulwinkel
bulwinkel / org-res.sh
Created January 15, 2018 03:01
script that moved imageRes-mdpi.png into res/mdpi/imageRes.png
RESOLUTIONS=('-mdpi' '-hdpi' '-xhdpi' '-xxhdpi' '-xxxhdpi')
for res in "${RESOLUTIONS[@]}"; do
echo $res
DIR="res/drawable${res}"
mkdir -p ${DIR}
for file in $(find . -type f -iname "*${res}*"); do
echo "${file}"
mv "$file" "${DIR}/${file/${res}/}"
done
@bulwinkel
bulwinkel / README_APPCENTER_SCRIPTS.md
Last active October 8, 2018 03:38
Hydric AppCenter Scripts: Post to slack for iOS

Hydric AppCenter Scripts for iOS

Currently these scripts post to slack when:

  • a build starts
  • a build finishes successfully

Usage Instructions

  1. Create an incoming webhook for the channel you would like these scripts to post to.
  2. Download and extract all the files from this gist into the root directory of your iOS project.
    If you have 'jq' installed (brew install jq) you can do this step with the following command from the root directory of your project:
    curl --silent "https://gist.github.com/bulwinkel/b1c371d447df071b90fe6e331d8b7d98/archive/$(http https://api.github.com/gists/b1c371d447df071b90fe6e331d8b7d98/commits | jq -r '.[0].version').zip" | tar --strip-components=1 -xf - -C .