Skip to content

Instantly share code, notes, and snippets.

Avatar

Wesley Bliss wesleybliss

View GitHub Profile
@wesleybliss
wesleybliss / simple_observer.kt
Created Mar 4, 2020
Simple Kotlin Observer Pattern
View simple_observer.kt
interface Observer<T> {
fun onChange(newValue: T?)
}
class Observable<T>(initialValue: T? = null) {
// List ov observers watching this value for changes
private val observers = mutableListOf<Observer<T>>()
// The real value of this observer
@wesleybliss
wesleybliss / IQueue.kt
Created Feb 28, 2020
IQueue - simple queue interface
View IQueue.kt
import java.util.concurrent.ConcurrentLinkedQueue
interface IQueue {
val tasks: ConcurrentLinkedQueue<String>
val hasTasks: Boolean
var isRunning: Boolean
fun addTask(url: String)
@wesleybliss
wesleybliss / BrotherPrinterTriageNonsense1.kt
Created Dec 2, 2019
Diagnosing some Brother printer SDK search weirdness
View BrotherPrinterTriageNonsense1.kt
fun publicGetUniqueDevSet() : Vector<DevSet?>? {
val finder = DeviceFinder()
val uniqueDevSet: Vector<DevSet?> = Vector()
val devSets = if (Printer.getUserPrinterInfo() == null) {
finder.discoverDevice(false)
} else {
finder.discoverDevice(Printer.getUserPrinterInfo().enabledTethering)
}
@wesleybliss
wesleybliss / PersistedLiveData.kt
Created Nov 22, 2019
LiveData implementation that reads/writes it's values to SharedPreferences via Hawk
View PersistedLiveData.kt
import android.content.SharedPreferences
import androidx.lifecycle.MutableLiveData
import androidx.preference.PreferenceManager
import com.orhanobut.hawk.Hawk
import com.splashthat.host.extensions.Plank
/**
* A [LiveData] implementation that reads and persists
* it's value using [SharedPreferences] via [Hawk]
*/
View git-prune
#!/usr/bin/env node
const shell = require('shelljs')
const inquirer = require('inquirer')
const chalk = require('chalk')
/**
* Gets a list of Git branches
*
* @return {Array[String]}
View RecyclerViewTouchHelper
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.splashthat.host.R
import com.splashthat.host.api.Identifiable
import com.splashthat.host.extensions.getColorDrawable
@wesleybliss
wesleybliss / KBus.kt
Created Dec 3, 2018
Kotlin event bus example
View KBus.kt
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.PublishSubject
/**
* Created by adrielcafe on 20/12/17.
*/
object KBus {
val disposables = mutableMapOf<Any, CompositeDisposable>()
val publishSubject = PublishSubject.create<Any>()!!
View memoized_fib.js
const fib = n => (n < 2) ? n : fib(n - 1) + fib(n - 2)
const fibSexy = (() => {
const cache = {}
const f = n => {
const value = (n in cache)
? cache[n]
@wesleybliss
wesleybliss / filter-keys.js
Created Jun 1, 2018
Filters an object returning only properties specified
View filter-keys.js
/**
* Filters an object returning only properties specified
*
* @param {Object} obj Source object
* @param {Array} keys List of (strings) properties to keep
* @return {Object} Object with only props specified in `keys`
*/
export const filterKeys = (obj, keepKeys, dropKeys) => {
if (typeof obj !== 'object')
@wesleybliss
wesleybliss / debounce.js
Created Apr 28, 2018
Debounce a function
View debounce.js
/**
* Creates a debounced monad to allow a method to be called
* many times, but only execute after N seconds has elapsed
*
* @param {Function} func Method to call
* @param {Number} wait Timeout, in milliseconds
* @param {Boolean} [immediate] Optionally skip the wait
* @return {Function} Debounced monad that can be called multiple times
*/
export function debounce(func, wait, immediate) {
You can’t perform that action at this time.