Skip to content

Instantly share code, notes, and snippets.

View mcbarin's full-sized avatar

Mehmet Çağatay Barın mcbarin

  • Crowd Data Systems
  • Colchester
View GitHub Profile
@AliRn76
AliRn76 / Django_Channels3_Custom_Auth_Middleware.py
Last active April 10, 2025 16:38
Token authorization middleware for Django Channels 3
from django.contrib.auth.models import AnonymousUser
from rest_framework.authtoken.models import Token
from channels.db import database_sync_to_async
from channels.middleware import BaseMiddleware
from project.settings import SIMPLE_JWT, SECRET_KEY
@database_sync_to_async
def get_user(token_key):
# If you are using normal token based authentication
try:
#! /usr/bin/python
#improvement of Weslley S Pereira's script by Jacob Trock
try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
@harshithjv
harshithjv / kill_celery_processes.sh
Last active February 18, 2024 10:20
Killing all celery processes in one line.
# Killing all celery processes involves 'grep'ing on 'ps' command and run kill command on all PID. Greping
# on ps command results in showing up self process info of grep command. In order to skip that PID, 'grep
# -v grep' command is piplined which executes 'not' condition on 'grep' search key. The 'awk' command is
# used to filter only 2nd and 'tr' command translates result of 'awk' command output from rows to columns.
# Piplining 'kill' command did not work and so the entire process has been set as command substitution, i.e.,
# '$()'. The redirection at the end is not mandatory. Its only to supress the enitre output into background.
kill -9 $(ps aux | grep celery | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1
@anandwana001
anandwana001 / OnButtonClick.java
Last active July 14, 2020 10:26
Save image from network to external storage using Glide
#Step 1
Glide.with(mContext)
.load(images.get(position).getThumbnail())
.asBitmap()
.into(new SimpleTarget<Bitmap>(100,100) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
saveImage(resource,position);
}
});
import functools
from channels.handler import AsgiRequest
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.settings import api_settings
authenticators = [auth() for auth in api_settings.DEFAULT_AUTHENTICATION_CLASSES]
@faruktoptas
faruktoptas / KeyboardSensitiveRelativeLayout.java
Last active November 3, 2023 17:50
A layout that detects Soft Keyboard is visible or not.
public class KeyboardSensitiveRelativeLayout extends RelativeLayout {
private OnKeyboardShowHideListener listener;
public KeyboardSensitiveRelativeLayout(Context context) {
super(context);
}
public KeyboardSensitiveRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@bulwinkel
bulwinkel / mapToBundle.kt
Created January 7, 2017 13:35
Partial implementation of converting a `Map<String, V>` to a Bundle.
package com.bulwinkel.android
import android.os.Bundle
import android.os.IBinder
import android.os.Parcelable
import java.io.Serializable
fun <V> Map<String, V>.toBundle(bundle: Bundle = Bundle()): Bundle = bundle.apply {
forEach {
val k = it.key
@f3401pal
f3401pal / ListShimmerView.java
Last active August 5, 2021 16:37
ListShimmerView
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
@IrSent
IrSent / celery.py
Created November 12, 2016 19:12
Celery Best Practices
# Safe Queue Celery App Settings
from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('some_project',
broker='amqp://',
backend='amqp://',
include=['some_project.tasks'])
@yushaojian13
yushaojian13 / ImageSaveTask.java
Last active July 24, 2020 16:46
A task to download and save image to SD card with Glide
public class ImageSaveTask extends AsyncTask<String, Void, Void> {
private Context context;
public ImageSaveTask(Context context) {
this.context = context;
}
@Override
protected Void doInBackground(String... params) {
if (params == null || params.length < 2) {