Skip to content

Instantly share code, notes, and snippets.

View vklachkov's full-sized avatar

Valera Klachkov vklachkov

View GitHub Profile
@vklachkov
vklachkov / lost_focus_on_misclick.kt
Created February 10, 2020 19:43
Removing focus from the input field automatically when you click in any other area
// Put it in your Activity and it'll apply to all EditTexts including those within fragments within that activity
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_DOWN) {
val v = currentFocus
if (v is EditText) {
val outRect = Rect()
v.getGlobalVisibleRect(outRect)
if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) {
v.clearFocus()
val imm: InputMethodManager =
@vklachkov
vklachkov / bytes_macroses.c
Created January 25, 2020 00:42
Macros that simplify working with individual bytes
#define GET_BYTE(val, n) (((val) >> (8*(n))) & 0xFF)
#define GET_BYTE_FROM_END(val, n) (((val) >> (8*(sizeof((val)) - 1 - (n)))) & 0xFF)
#define BSWAP16(val) \
( (((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00) )
#define BSWAP32(val) \
( (((val) >> 24) & 0x000000FF) | (((val) >> 8) & 0x0000FF00) | \
(((val) << 8) & 0x00FF0000) | (((val) << 24) & 0xFF000000) )
@vklachkov
vklachkov / runlistgen.c
Created January 25, 2020 00:40
Generates an entry from the RunList and outputs it in byte order
/* INCLUDES *******************************************************************/
#include <stdio.h>
#include <stdlib.h>
/* TYPES **********************************************************************/
#define BYTE unsigned char
#define PBYTE BYTE*