Skip to content

Instantly share code, notes, and snippets.

View sevar83's full-sized avatar

Svetlozar Kostadinov sevar83

View GitHub Profile
@wajahatkarim3
wajahatkarim3 / ActivitiesLaunchingWay.kt
Last active April 3, 2023 08:12
Kotlin Extensions for simpler, easier and funw way of launching of Activities
/**
* Kotlin Extensions for simpler, easier and funw way
* of launching of Activities
*/
inline fun <reified T : Any> Activity.launchActivity (
requestCode: Int = -1,
options: Bundle? = null,
noinline init: Intent.() -> Unit = {})
{
@wispborne
wispborne / ViewOnceData.kt
Last active October 3, 2018 08:14
A class that encapsulates data, adding ability to know when the data has already been viewed. Useful for putting one-shot events, like "display dialog", into a State object that can be reapplied to a view.
import java.util.concurrent.atomic.AtomicBoolean
/**
* Wraps some data that should track when it has been viewed and allow future viewers to avoid a second showing.
* Useful for showing messages in the app that auto-hide because this class can exist in the app's state.
*/
data class ViewOnceData<T>(private val data: T) {
val wasViewed = AtomicBoolean(false)
/**
@internetmosquito
internetmosquito / gist:b1c1f00ac99d9aa1f79cfdc21be36b5b
Last active June 11, 2018 10:32
How to encode images for Google Cloud Vision
images_names = list()
for iterator, image_file in enumerate(images):
image_path = os.path.join(folder_name, image_file)
images_names.append(self.path_leaf(image_path))
self.images_names.append(self.path_leaf(image_path))
with open(image_path, 'rb') as image:
image_content = base64.b64encode(image.read())
image_payload = {}
image_payload['image'] = {}
image_payload['image']['content'] = image_content.decode('UTF-8')
@vestrel00
vestrel00 / Dagger2SimpleExample.java
Last active October 7, 2021 19:59
A: Dagger.android 2.11 simple example with support for Singleton, PerActivity, PerFragment, and PerChildFragment scopes
// This is a super simplified example of how to use the new dagger.android framework
// introduced in Dagger 2.10. For a more complete, in-depth guide to dagger.android
// read https://proandroiddev.com/how-to-android-dagger-2-10-2-11-butterknife-mvp-part-1-eb0f6b970fd
// For a complete codebase using dagger.android 2.11-2.17, butterknife 8.7-8.8, and MVP,
// see https://github.com/vestrel00/android-dagger-butterknife-mvp
// This example works with Dagger 2.11-2.17. Starting with Dagger 2.11,
// @ContributesAndroidInjector was introduced removing the need to define @Subcomponent classes.
@yanngx
yanngx / FragmentArgumentDelegate.kt
Last active January 19, 2023 09:26
Fragment arguments without hassle !
package be.brol
import android.os.Binder
import android.os.Bundle
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
/**
* Eases the Fragment.newInstance ceremony by marking the fragment's args with this delegate
* Just write the property in newInstance and read it like any other property after the fragment has been created
class FooActivity extends MviActivity<...> {
@Inject FooPresenter
public void onCreate(Bundle bundle){
super.onCreate(bundle);
FooComponent component = DaggerFooComponent.builder()
.fooModule(new FooModule(bundle))
.build();
component.inject(this);
@iago-suarez
iago-suarez / opencv-opencl-android.md
Last active September 10, 2024 05:34
Setting Up OpenCL for OpenCV on Android, the full story

Setting Up OpenCL for OpenCV on Android, the full story

The tutorial Use OpenCL in Android camera preview based CV application show us how we can use the Transparent API to dramatically increase the performance of some expensive operations.

The first step in order to be able to execute the tutorial example is to re-compile opencv with the correct flags:

# Export your NDK, it will be looked for OpenCV to compile your project. In my case
export ANDROID_NDK=~/graffter/libs/android-ndk-r10d/

# Download the necessary code
@andymatuschak
andymatuschak / States-v3.md
Last active November 14, 2024 18:33
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,

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- google's material design colours from
http://www.google.com/design/spec/style/color.html#color-ui-color-palette -->
<!--reds-->
<color name="md_red_50">#FFEBEE</color>
<color name="md_red_100">#FFCDD2</color>
<color name="md_red_200">#EF9A9A</color>