Skip to content

Instantly share code, notes, and snippets.

View devahmedshendy's full-sized avatar

Ahmed Shendy devahmedshendy

  • Egypt
View GitHub Profile
@alokomkar
alokomkar / gist:6302b91be1e3c1b1badcab2552e2b5bc
Created October 13, 2019 07:47
RxObservable based Broadcast receiver
fun AppCompatActivity.subscribeToBroadcastsOnLifecycle(action: String, fn: (Intent) -> Unit) {
observeBroadcasts(action).subscribeOnLifecycle(lifecycle, fn)
}
fun <T> Observable<T>.subscribeOnLifecycle(lifecycle: Lifecycle, fn: (T) -> Unit) {
val lifecycleObserver: LifecycleObserver = object : LifecycleObserver {
private var subscription: Disposable? = null
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onStart() {
@HiImJulien
HiImJulien / Swift Meets CCxx.md
Last active March 30, 2024 19:00
This gist is a simple example on how to call a function written in swift from C/C++, without taking the detour via Objective-C/C++.

Swift Meets C/C++

This gist is a simple example on how to call a function written in swift from C/C++, without taking the detour via Objective-C/C++.


Analytics

In this example we're going to invoke a function called say_hello, which, as the name already suggests, prints "Hello, World!" to the terminal.

@andymatuschak
andymatuschak / States-v3.md
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,