Skip to content

Instantly share code, notes, and snippets.

View vklachkov's full-sized avatar
🏠
Working from home

Valery Klachkov vklachkov

🏠
Working from home
View GitHub Profile
@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*
@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 / 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 / tcp_echo_client.py
Created April 3, 2020 22:14
Simple tcp echo client
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('SERVER', 80))
while True:
raw = s.recv(1024)
print(raw.decode('ascii'))
@vklachkov
vklachkov / tcp_counter_server.py
Created April 14, 2020 18:03
Simple tcp server
import socket
import time
SERVER_ADDRESS = ('localhost', 2353)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(SERVER_ADDRESS)
server_socket.listen(1)
while True:
@vklachkov
vklachkov / diskutils_ntfs_vhdx_format.cs
Created April 14, 2020 18:11
C# example which create vhdx disk and create empty ntfs volume using DiskUtils
using System.IO;
using DiscUtils;
using DiscUtils.Ntfs;
using DiscUtils.Partitions;
using DiscUtils.Streams;
using DiscUtils.Vhdx;
namespace App
{
internal class Program
@vklachkov
vklachkov / ya_taxi_money.py
Created April 22, 2020 10:35
Calculates the amount of money spent on taxis from a message backup
import re
money = 0
with open("raw.txt", encoding="utf-8") as f:
for line in f.readlines():
if "YANDEX.TAXI" not in line:
continue
data = line.strip()
@vklachkov
vklachkov / mqtt.kt
Last active March 14, 2021 13:04
Coroutines over mqtt android client
package mqtt
import kotlinx.coroutines.suspendCancellableCoroutine
import org.eclipse.paho.android.service.MqttAndroidClient
import org.eclipse.paho.client.mqttv3.*
import timber.log.Timber
import kotlin.coroutines.resume
suspend inline fun MqttAndroidClient.awaitConnectWith(
crossinline options: MqttConnectOptions.() -> Unit
@vklachkov
vklachkov / android_text_input_layout.xml
Last active April 1, 2021 09:18
Colorize TextInputLayout.FilledBox
<!-- See: -->
<!-- https://medium.com/omisoft/textinputlayout-styling-8b36a5e0d73c -->
<!-- Style and color must be placed into different files -->
<!-- Style -->
<style name="TextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="hintTextColor">@color/input_box_color</item>
<item name="passwordToggleTint">@color/input_box_color</item>
<item name="boxStrokeColor">@color/input_box_color</item>
# Реклама групп с пометкой рекламы
vk.com#?##page_wall_posts > div[id^="post-"]:-abp-has(.wall_marked_as_ads)
# Реклама интересных авторов
vk.com#?##page_wall_posts > div[id^="post-"]:-abp-has(.wall_authors_rec)
# Рекомендации в ленте
vk.com##.feed_friends_recomm
vk.com###profile_friends_recomm