Skip to content

Instantly share code, notes, and snippets.

View edujtm's full-sized avatar
🐢
Studying

Eduardo José Tomé de Macedo edujtm

🐢
Studying
View GitHub Profile
@JonCatmull
JonCatmull / rxjs-localstorage-replay.ts
Last active January 27, 2023 10:51
RXJS operator function to store a stream in localStorage, then replays from localStorage when provided BehaviourSubject is true. This is helpful if you need to replay a complicated set of observable streams after a browser redirect.
/**
* Stores last emitted value in localStorage and replays if usStore$ is set.
* If usStore$ is truthy then switches stream to use stored value.
* If usStore$ is undefined then stream will emit as normal.
* @param storageKey unique key to use in localStorage
* @param useStore$ controls if the localStorage value is used
*/
export default function localStorageReplay<T>(storageKey: string, useStore$: BehaviorSubject<boolean>): MonoTypeOperatorFunction<T> {
return (input$): Observable<T> => {
@kakai248
kakai248 / Example.kt
Created February 24, 2020 18:00
Example on how to to inject SavedStateHandle into ViewModel's
// ViewModel factory
@MainThread
inline fun <reified VM : ViewModel> ComponentActivity.viewModel(
noinline provider: (SavedStateHandle) -> VM
) = createLazyViewModel(
viewModelClass = VM::class,
savedStateRegistryOwnerProducer = { this },
viewModelStoreOwnerProducer = { this },
viewModelProvider = provider
@androidfred
androidfred / kotlin_arrow.md
Last active December 7, 2023 17:42
Kotlin Arrow

Kotlin Arrow

A lot of Kotlin features can be traced back to functional programming languages, eg

  • Heavy use of immutability-by-default and map, filter etc functions
  • Type inference
  • Data classes (which enable pattern matching)
  • Null safety and dealing with the absence of values

However, Kotlin is missing many incredibly useful data types that are ubiquitous in functional programming languages, eg Either, Try etc.

@swlaschin
swlaschin / FsCsInterop.md
Last active April 7, 2024 20:33
F# to C# interop tips

Tips on exposing F# to C#

Api and Methods

I suggest that you create one or more Api.fs files to expose F# code in a C# friendly way.

In this file:

  • Define functions with PascalCase names. They will appear to C# as static methods.
  • Functions should use tuple-style declarations (like C#) rather than F#-style params with spaces.
@Viska97
Viska97 / TestBoundaryCallback.kt
Last active March 7, 2019 17:42
PagedList.BoundaryCallback with coroutines
class TestBoundaryCallback(
private val pageSize: Int,
private val dataSource: BackendDataSource,
private val database : AppDatabase
) : PagedList.BoundaryCallback<?>(){
var networkState = MutableLiveData<Int>()
private var isRequestInProgress = false
@felix19350
felix19350 / ktor-full-example.kt
Last active July 15, 2023 12:42
Barebones Ktor REST API example
package org.example
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.request.receive
import io.ktor.response.respond
import io.ktor.routing.Route
import io.ktor.routing.get
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@santrancisco
santrancisco / VagrantFile
Created March 19, 2018 00:55
VagrantFile for official base image - windows 10 with Microsoft edge
# -*- mode: ruby -*-
# vi: set ft=ruby :
## Thanks to the discussion of various developers in this gist
## https://gist.github.com/andreptb/57e388df5e881937e62a#gistcomment-2346821
## Especially clement-igonet.
### How to get Windows10 with Edge official base image run with WinRM and RDP:
# To use Windows10-Edge vagrant you will first need to download https://aka.ms/msedge.win10.vagrant (this is now a zip file)
# Execute `vagrant box add ./MsEdge\ -\ Win10.box --name Win10-official` after unzip the file to add the box to our base image list
@ckimrie
ckimrie / example.component.ts
Last active December 12, 2023 20:53
Example on how to achieve RxJS observable caching and storage in Angular 2+. Ideal for storing Http requests client side for offline usage.
import { Component, OnInit, OnDestroy } from '@angular/core';
import {Http} from "@angular/http";
import { LocalCacheService } from "./local-cache.service";
@Component({
selector: 'app-example',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class ExampleComponent implements OnInit, OnDestroy {
@btroncone
btroncone / bootstrap.ts
Last active May 10, 2021 20:53
Basic demonstration of how NgRx middleware can be used to keep local storage in sync with user-defined state slices.
//specify what state slices you would like to keep synced with local storage
export function main() {
return bootstrap(TodoApp, [
provideStore(APP_REDUCERS),
localStorageMiddleware('todos', 'visibilityFilter')
])
.catch(err => console.error(err));
}