Skip to content

Instantly share code, notes, and snippets.

View muth0mi's full-sized avatar
:octocat:
Always writing some Kotlin somewhere.

Oliver Muthomi muth0mi

:octocat:
Always writing some Kotlin somewhere.
View GitHub Profile
@safaorhan
safaorhan / ViewPager2Hack.kt
Created February 11, 2020 13:45
Disables the child attach listener so that inflated children with wrap_content heights can pass.
/**
* Disables the child attach listener so that inflated children with wrap_content heights can pass.
*
* This is very fragile and depends on the implementation details of [ViewPager2].
*
* @see ViewPager2.enforceChildFillListener (the removed listener)
*/
private fun ViewPager2.hackMatchParentCheckInViewPager() {
(getChildAt(0) as RecyclerView).clearOnChildAttachStateChangeListeners()
}
@andreagrandi
andreagrandi / permissions.py
Created September 30, 2016 09:49
IsAdminOrReadOnly is a custom Django Rest Framework permission class that allows Admin users to POST and anonymous to GET
from rest_framework.permissions import BasePermission, SAFE_METHODS
class IsAdminOrReadOnly(BasePermission):
def has_permission(self, request, view):
if request.method in SAFE_METHODS:
return True
else:
return request.user.is_staff