Skip to content

Instantly share code, notes, and snippets.

View JorgeCastilloPrz's full-sized avatar
🎉
Mostly Android stuff now, also FP

Jorge Castillo JorgeCastilloPrz

🎉
Mostly Android stuff now, also FP
View GitHub Profile
@JorgeCastilloPrz
JorgeCastilloPrz / RatingStars.kt
Last active August 29, 2021 23:43
Composable to show rating stars. Noninteractive.
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.Composable
import androidx.ui.core.Modifier
import androidx.ui.core.tag
import androidx.ui.foundation.Text
import androidx.ui.foundation.drawBackground
import androidx.ui.graphics.Color
import androidx.ui.layout.ConstraintLayout
import androidx.ui.layout.ConstraintSet
import androidx.ui.layout.fillMaxWidth
import androidx.ui.layout.padding
@JorgeCastilloPrz
JorgeCastilloPrz / FunctionalAndroidSolutions.kt
Created July 1, 2020 07:53
Functional Android workshop exercise solutions
// 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 {
@JorgeCastilloPrz
JorgeCastilloPrz / PolymorphicProgram.kt
Last active May 23, 2020 08:16
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
JorgeCastilloPrz / RxApp.kt
Created July 30, 2018 16:14
Sample snippet for a canonical problem resolved using RxJava
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
JorgeCastilloPrz / MyFlutterFabLoaderApp.kt
Created June 4, 2019 18:26
This is a simple sample app for running our custom StatefulWidget.
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FabLoader Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
@JorgeCastilloPrz
JorgeCastilloPrz / FabLoadingWidget.kt
Created June 4, 2019 18:14
Stateful widget used to retain animations to calculate values for painting the arc.
class _FabLoadingWidget extends State<FabLoader>
with SingleTickerProviderStateMixin {
final Widget child;
final double strokeWidth;
AnimationController _controller;
_FabLoadingWidget({@required this.strokeWidth, @required this.child});
@override
@JorgeCastilloPrz
JorgeCastilloPrz / ArcRotationTween.kt
Created June 4, 2019 18:08
Arc rotation Tween curve
final Animatable<double> _kRotationTween = CurveTween(curve: const SawTooth(5));
@JorgeCastilloPrz
JorgeCastilloPrz / StepTween.kt
Created June 4, 2019 18:04
Current arc progress StepTween
final Animatable<int> _kStepTween = StepTween(begin: 0, end: 5);
@JorgeCastilloPrz
JorgeCastilloPrz / ArcTailTween.kt
Created June 4, 2019 18:01
Arc tail animation Tween.
final Animatable<double> _kStrokeTailTween = CurveTween(
curve: const Interval(0.5, 1.0, curve: Curves.fastOutSlowIn),
).chain(CurveTween(
curve: const SawTooth(5),
));