Skip to content

Instantly share code, notes, and snippets.

View FragmentViewBindingDelegate.kt
// https://github.com/Zhuinden/fragmentviewbindingdelegate-kt
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty
@Andrej1A
Andrej1A / ViewLifecycleBinding.kt
Created May 4, 2021 — forked from jamiesanson/ViewLifecycleBinding.kt
Kotlin Property Delegate for Fragment view lifecycle binding
View ViewLifecycleBinding.kt
fun <T> Fragment.viewLifecycle(bindUntilEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY): ReadWriteProperty<Fragment, T> =
object: ReadWriteProperty<Fragment, T>, LifecycleObserver {
// A backing property to hold our value
private var binding: T? = null
private var viewLifecycleOwner: LifecycleOwner? = null
init {
// Observe the View Lifecycle of the Fragment
@Andrej1A
Andrej1A / start_wsgi_server.sh
Created Jul 13, 2020
Script to start wsgi server for Django
View start_wsgi_server.sh
#!/bin/sh
# NOTE: this script will be executed inside a docker container
# parameter
# start_wsgi_server.sh dev sms_api_gateway.settings.cloud_dev
if [ $# -ne 2 ]; then
echo $0: usage: start_wsgi_server.sh DJANGO_ENV DJANGO_SETTINGS
exit 1
@Andrej1A
Andrej1A / entrypoint.sh
Created Jul 13, 2020
entry point for Django application
View entrypoint.sh
#!/bin/bash
set -e
cmd="$@"
function postgres_ready(){
python << END
import sys
import psycopg2
try:
@Andrej1A
Andrej1A / Dockerfile
Created Jul 13, 2020
Dockerfile for Django-Application
View Dockerfile
FROM python:3.6-stretch
ARG DJANGO_ENV=dev
ENV PYTHONUNBUFFERED 1
# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./requirements/base.txt /base.txt
COPY ./requirements/cloud_production.txt /cloud_production.txt
COPY ./requirements/${DJANGO_ENV}.txt /requirements_${DJANGO_ENV}.txt
View Create_docker.sh
#!/bin/bash
docker build \
--file Dockerfile \
--tag registry.andrej-albrecht.com/sms-api-gateway/sag-web-backend/cloud_test:latest \
--build-arg DJANGO_ENV=cloud_test \
.
@Andrej1A
Andrej1A / android-kotlin-custom-view-template
Last active Sep 25, 2019
Template for an Android custom view. The example shows a vertical dotted line.
View android-kotlin-custom-view-template
/**
* VerticalDottedLineView
* Add to attrs.xml:
* <declare-styleable name="VerticalDottedLineView">
* <attr name="dots_color" format="color" />
* </declare-styleable>
*/
class VerticalDottedLineView : View {
private var dotColor: Int = 0
@Andrej1A
Andrej1A / Android-Tint-LottieAnimationView.kt
Created Sep 11, 2019
Android Kotlin Tint LottieAnimationView JSON
View Android-Tint-LottieAnimationView.kt
/**
* Tint LottieAnimationView
*/
private fun LottieAnimationView.tintColor(@ColorInt tintColor: Int) {
addValueCallback(
KeyPath("**"),
LottieProperty.COLOR_FILTER,
{ PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_ATOP) }
)
}
@Andrej1A
Andrej1A / Connectivity.java
Created Feb 14, 2019 — forked from emil2k/Connectivity.java
Android utility class for checking device's network connectivity and speed.
View Connectivity.java
/*
* Copyright (c) 2017 Emil Davtyan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@Andrej1A
Andrej1A / premailer.py
Created Feb 2, 2019 — forked from isaac-jordan/premailer.py
An updated version of django-premailer that works with Django 1.9 and Python 3.
View premailer.py
# Put in 'templatetags' folder in your Django app.
from __future__ import absolute_import
from django import template
from django.utils.encoding import smart_text
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage
from django.conf import settings
from premailer import Premailer