Skip to content

Instantly share code, notes, and snippets.

Avatar

Svetlozar Kostadinov sevar83

View GitHub Profile
@wajahatkarim3
wajahatkarim3 / ActivitiesLaunchingWay.kt
Last active Jun 24, 2021
Kotlin Extensions for simpler, easier and funw way of launching of Activities
View ActivitiesLaunchingWay.kt
/**
* 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 = {})
{
@davidwhitman
davidwhitman / ViewOnceData.kt
Last active Oct 3, 2018
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.
View ViewOnceData.kt
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 Jun 11, 2018
How to encode images for Google Cloud Vision
View gist:b1c1f00ac99d9aa1f79cfdc21be36b5b
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 Nov 2, 2020
A: Dagger.android 2.11 simple example with support for Singleton, PerActivity, PerFragment, and PerChildFragment scopes
View Dagger2SimpleExample.java
// 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 Feb 20, 2021
Fragment arguments without hassle !
View FragmentArgumentDelegate.kt
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
View FooActivity.java
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 Sep 14, 2020
Setting Up OpenCL for OpenCV on Android, the full story
View opencv-opencl-android.md

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 Jun 24, 2021
A composable pattern for pure state machines with effects (draft v3)
View States-v3.md

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,

View android_material_design_colours.xml
<?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>