Skip to content

Instantly share code, notes, and snippets.

View aballano's full-sized avatar
🏠
Working from home

Alberto Ballano aballano

🏠
Working from home
View GitHub Profile
@jdegoes
jdegoes / fpmax.scala
Created July 13, 2018 03:18
FP to the Max β€” Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@raulraja
raulraja / dstagless.kt
Last active December 15, 2018 01:23
Tagless data source strategies with Arrow
import arrow.Kind
import arrow.core.Option
import arrow.core.left
import arrow.core.right
import arrow.effects.typeclasses.Async
import arrow.typeclasses.ApplicativeError
data class UserId(val value: String)
data class User(val userId: UserId)
data class Task(val value: String)
@jmfayard
jmfayard / DataTypeExamples.kt
Last active November 27, 2017 18:00
Functional datatypes & abstractions for Kotlin http://kategory.io/
package kategory
import io.kotlintest.matchers.*
import io.kotlintest.specs.FreeSpec
import kategory.Problem.*
import kotlin.reflect.KClass
/*** Kategory.io documentation as runnable code ***/
class DataTypeExamples : FreeSpec() { init {
@sinbad
sinbad / LightFlickerEffect.cs
Last active March 29, 2025 02:16
Unity simple & fast light flicker script
using UnityEngine;
using System.Collections.Generic;
// Written by Steve Streeting 2017
// License: CC0 Public Domain http://creativecommons.org/publicdomain/zero/1.0/
/// <summary>
/// Component which will flicker a linked light while active by changing its
/// intensity between the min and max values given. The flickering can be
/// sharp or smoothed depending on the value of the smoothing parameter.
@chrisbanes
chrisbanes / KotterKnife.kt
Last active February 7, 2021 15:25
LifecycleAware KotterKnife
package kotterknife
import android.app.Activity
import android.app.Dialog
import android.app.DialogFragment
import android.app.Fragment
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.OnLifecycleEvent
@strooooke
strooooke / choose_device.sh
Created April 29, 2017 11:57
Wrapper script for adb commands (and pidcat!) that take a -s device serial argument, allowing to choose between devices
#!/bin/bash
# Prompts for device to use from adb devices -l first; inserts -s parameter.
# No sanitizing, error checking or warranties!
# Use like
# $choose_device adb shell
DEVICES=`adb devices -l | sed 1d`
PS3="Choose device or Ctrl+C to quit: "
Type Functor Apply Applicative Bind Monad MonoidK MonadError Cobind Comonad
Id[A] βœ” βœ” βœ” βœ” βœ” βœ— βœ— βœ” βœ”
Option[A] βœ” βœ” βœ” βœ” βœ” βœ” βœ— βœ” βœ—
Const[K, A] βœ” βœ” (K:Monoid) βœ” βœ— βœ— βœ— βœ— ? ?
Either[E, A] βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ— βœ—
List[A] βœ” βœ” βœ” βœ” βœ” βœ” βœ— βœ” βœ—
NonEmptyList[A] βœ”
@jsaund
jsaund / rx_search_result_improved.java
Created February 23, 2017 21:17
Demonstrates using onErrorResumeNext to prevent terminating the upstream sequence. Notice that the onErrorResumeNext is applied inside the switchMap rather than outside.
public Observable<SearchResult> search(@NotNull EditText searchView) {
return RxTextView.textChanges(searchView) // In production, share this text view observable, don't create a new one each time
.map(CharSequence::toString)
.debounce(500, TimeUnit.MILLISECONDS) // Avoid getting spammed with key stroke changes
.filter(s -> s.length() > 1) // Only interested in queries of length greater than 1
.observeOn(workerScheduler) // Next set of operations will be network so switch to an IO Scheduler (or worker)
.switchMap(query -> searchService.query(query) // Take the latest observable from upstream and unsubscribe from any previous subscriptions
.onErrorResumeNext(Observable.empty()); // <-- This fixes the problem since the error is not seen by the upstream observable
}
@serj-lotutovici
serj-lotutovici / GenericPolymorphicJsonAdapterFactory.java
Last active May 8, 2022 19:45
A Moshi JsonAdapter.Factory that creates Polymorphic JsonAdapter. Requires Moshi 1.4.0. (Tests written in kotlin)
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonDataException;
import com.squareup.moshi.JsonReader;
import com.squareup.moshi.JsonWriter;
import com.squareup.moshi.Moshi;
import com.squareup.moshi.Types;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
@AlecKazakova
AlecKazakova / BriteDatabaseUtils.kt
Last active February 7, 2021 15:36
Extension functions on SQLBrite's BriteDatabase to make working with SQLDelight easier
fun BriteDatabase.createQuery(query: SqlDelightStatement) = createQuery(query.tables, query.statement, *query.args)
inline fun <T: SqlDelightCompiledStatement> BriteDatabase.bindAndExecute(compiledStatement: T, bind: T.() -> Unit): Long {
synchronized(compiledStatement) {
compiledStatement.bind()
return when (compiledStatement) {
is SqlDelightCompiledStatement.Insert -> {
executeInsert(compiledStatement.table, compiledStatement.program)
}
is SqlDelightCompiledStatement.Update -> {