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 / 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
@Andrej1A
Andrej1A / translate.py
Created May 23, 2017 — forked from jseabold/translate.py
Use Google Translate API from Python
View translate.py
# -*- coding: utf-8 -*-
"""
You need to fill in your API key from google below. Note that querying
supported languages is not implemented.
Language Code
-------- ----
Afrikaans af
Albanian sq
Arabic ar
@Andrej1A
Andrej1A / routers.py
Created May 8, 2017 — forked from artschwagerb/routers.py
Django Database Routers Master-Slave
View routers.py
import random
class MasterSlaveRouter(object):
def db_for_read(self, model, **hints):
"""
Reads go to a randomly-chosen slave.
"""
return random.choice(['master','slave1', 'slave2'])
def db_for_write(self, model, **hints):
@Andrej1A
Andrej1A / fabfile.py
Created Apr 11, 2017 — forked from fiee/fabfile.py
fabric fabfile.py for deployment of django apps on Debian servers
View fabfile.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
fabfile for Django
------------------
see http://morethanseven.net/2009/07/27/fabric-django-git-apache-mod_wsgi-virtualenv-and-p/
modified for fabric 0.9/1.0 by Hraban (fiëé visuëlle)
several additions, corrections and customizations, too
@Andrej1A
Andrej1A / CsvResponse.php
Created Nov 14, 2015 — forked from mathewbyrne/CsvResponse.php
A small Symfony 2 class for returning a response as a CSV file. Based on the Symfony JsonResponse class.
View CsvResponse.php
<?php
namespace Jb\AdminBundle\Http;
use Symfony\Component\HttpFoundation\Response;
class CsvResponse extends Response
{
protected $data;