Skip to content

Instantly share code, notes, and snippets.

@curioustechizen
curioustechizen / KotlinSide.kt
Created September 18, 2024 06:54
KMP-Swift: Return a Flow from Swift
interface SomeRepo {
val selectedProfileFlow: Flow<String>
}
// iosMain
interface ProfileObserver {
fun startObserving(onChange: (String) -> Unit)
fun stopObserving()
}
@curioustechizen
curioustechizen / main.dart
Created May 22, 2020 11:56
Flutter stateless widget blog: Step 3 - Use AnimatedContainer to use a Stateless Widget
import 'package:flutter/material.dart';
const kSelectedColor = Colors.blueAccent;
const kUnselectedColor = Colors.transparent;
const kSelectedShadowOffset = Offset(0.0, 4.0);
final kSelectedBorderRadius = BorderRadius.circular(32.0);
void main() {
runApp(MyApp());
}
@curioustechizen
curioustechizen / main.dart
Created May 22, 2020 11:21
Flutter stateless widget blog: Step 2 - Toggle animation with an isSelected state
import 'package:flutter/material.dart';
const kSelectedColor = Colors.blueAccent;
const kUnselectedColor = Colors.transparent;
const kSelectedShadowOffset = Offset(0.0, 4.0);
final kSelectedBorderRadius = BorderRadius.circular(32.0);
void main() {
runApp(MyApp());
}
@curioustechizen
curioustechizen / main.dart
Created May 22, 2020 11:01
Flutter stateless widget blog: Step 1 - One-time animation
import 'package:flutter/material.dart';
const kSelectedColor = Colors.blueAccent;
const kUnselectedColor = Colors.transparent;
const kSelectedShadowOffset = Offset(0.0, 4.0);
final kSelectedBorderRadius = BorderRadius.circular(32.0);
void main() {
runApp(MyApp());
}
@curioustechizen
curioustechizen / LiveDataScanOperator.kt
Created January 23, 2019 15:44
Analog of RxJava's Observable.scan operator for Android Architecture Components LiveData
/**
* Analog of RxJava's Observable.scan operator.
*
* Returns a LiveData that applies the [accumulator] function to the fist item in the source LiveData,
* and an initial value, then feeds the result of that function along with the second item emitted by
* the source LiveData into the same function, and so on until all items have been emitted by the source
* LiveData, emitting the result of each of these iterations.
*/
fun <T, R> LiveData<T>.scan(initialValue: R, accumulator: (R, T) -> R): LiveData<R> {
val returnLiveData = MediatorLiveData<R>()
@curioustechizen
curioustechizen / CascadingCustomLayout.java
Created March 19, 2018 08:33
Android: Cascade the value of a custom attribute from a parent view to a child view - solution to https://stackoverflow.com/q/15112522/570930
// See https://stackoverflow.com/q/15112522/570930
class CustomLayout extends WhateverLayout {
private float percent;
private CustomView customView;
//View constructors go here
private void init(){
//Inflation goes here if needed
class EspressoTextInputLayoutUtils{
/*
* Use this method to find the EditText within the TextInputLayout. Useful for typing into the TextInputLayout
*/
public static ViewInteraction onEditTextWithinTilWithId(@IdRes int textInputLayoutId) {
//Note, if you have specified an ID for the EditText that you place inside
//the TextInputLayout, use that instead - i.e, onView(withId(R.id.my_edit_text));
return onView(allOf(isDescendantOfA(withId(textInputLayoutId)), isAssignableFrom(EditText.class)));
}
@curioustechizen
curioustechizen / MainActivity.java
Last active September 16, 2015 13:10
Android Visibility save/restore: Quick gist to demonstrate the fact that the visibility of views is not preserved across screen rotation or other save/restore cycles.
public class MainActivity extends Activity {
private TextView tvHello;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.layout);
tvHello = (TextView) findViewById(R.id.tv_hello);
}
@curioustechizen
curioustechizen / js_revealing_module_snippet.js
Created July 10, 2015 13:52
Snippet for Visual Studio Code that created a revealing module pattern with constructor in Javascript
"Revealing Module Pattern with constructor": {
"prefix": "reveal",
"body": [
"var ${1:ModuleName} = (function () {",
" var that,",
" constr = function (${2:constr_param}) {",
" that = this;",
" this.$2 = $2;",
" },",
"",
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}