Skip to content

Instantly share code, notes, and snippets.

Mostly Android stuff now, also FP

Jorge Castillo JorgeCastilloPrz

Mostly Android stuff now, also FP
View GitHub Profile
View SampleRow.kt
import androidx.compose.Composable
import androidx.ui.core.Modifier
import androidx.ui.core.tag
import androidx.ui.layout.ConstraintLayout
import androidx.ui.layout.ConstraintSet
import androidx.ui.layout.fillMaxWidth
import androidx.ui.layout.padding
JorgeCastilloPrz / FunctionalAndroidSolutions.kt
Created Jul 1, 2020
Functional Android workshop exercise solutions
View FunctionalAndroidSolutions.kt
// Persistence.kt will end up looking like this after exercises 1 and 2.
fun stubPersistence(defaultAccounts: List<User>? = null, pool: CoroutineContext = IOPool) =
object : AccountPersistence {
private var accounts = defaultAccounts ?: emptyList()
private lateinit var updateTrigger: () -> Unit
override fun loadAccountsFromDatabase(): Stream<List<User>> = Stream(
Stream.async {
View PolymorphicProgram.kt
package me.jorgecastillo.polymorphicapps.polymorphic
import arrow.Kind
import arrow.core.Option
import arrow.core.left
import arrow.core.right
import arrow.effects.IO
import arrow.effects.async
import arrow.effects.fix
import arrow.effects.typeclasses.Async
JorgeCastilloPrz / RxApp.kt
Created Jul 30, 2018
Sample snippet for a canonical problem resolved using RxJava
View RxApp.kt
interface DataSource {
fun allTasksByUser(user: User): Observable<List<Task>>
class LocalDataSource : DataSource {
private val localCache: Map<User, List<Task>> =
mapOf(User(UserId("user1")) to listOf(Task("LocalTask assigned to user1")))
override fun allTasksByUser(user: User): Observable<List<Task>> = Observable.create { emitter ->
val cachedUser = localCache[user]
JorgeCastilloPrz / MyFlutterFabLoaderApp.kt
Created Jun 4, 2019
This is a simple sample app for running our custom StatefulWidget.
View MyFlutterFabLoaderApp.kt
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'FabLoader Demo',
theme: ThemeData(
home: Scaffold(
appBar: AppBar(
JorgeCastilloPrz / FabLoadingWidget.kt
Created Jun 4, 2019
Stateful widget used to retain animations to calculate values for painting the arc.
View FabLoadingWidget.kt
class _FabLoadingWidget extends State<FabLoader>
with SingleTickerProviderStateMixin {
final Widget child;
final double strokeWidth;
AnimationController _controller;
_FabLoadingWidget({@required this.strokeWidth, @required this.child});
View ArcRotationTween.kt
final Animatable<double> _kRotationTween = CurveTween(curve: const SawTooth(5));
JorgeCastilloPrz / StepTween.kt
Created Jun 4, 2019
Current arc progress StepTween
View StepTween.kt
final Animatable<int> _kStepTween = StepTween(begin: 0, end: 5);
JorgeCastilloPrz / ArcTailTween.kt
Created Jun 4, 2019
Arc tail animation Tween.
View ArcTailTween.kt
final Animatable<double> _kStrokeTailTween = CurveTween(
curve: const Interval(0.5, 1.0, curve: Curves.fastOutSlowIn),
curve: const SawTooth(5),
View ArcHeadTween.kt
final Animatable<double> _kStrokeHeadTween = CurveTween(
curve: const Interval(0.0, 0.5, curve: Curves.fastOutSlowIn),
curve: const SawTooth(5),
You can’t perform that action at this time.