Skip to content

Instantly share code, notes, and snippets.

@sertraline
sertraline / print_odd_even.asm
Created July 6, 2019 16:28
NASM: find odd and even characters in the string, save and print them
; NASM i386
; nasm -f elf print_odd_even.asm
; ld -m elf_i386 print_odd_even.o -o print_odd_even
;
; EXAMPLE
; bash# ./print_odd_even
; Enter the string: The quick brown fox jumps over the lazy dog
; Odd:
; Teqikbonfxjmsoe h aydg
; Even:
@sertraline
sertraline / tcvn3.py
Created November 7, 2020 03:51
TCVN3 to UTF-8
# TCVN3 to UTF-8
UNICODETAB = [
"À", "Á", "Â", "Ã", "È", "É", "Ê", "Ì", "Í", "Ò",
"Ó", "Ô", "Õ", "Ù", "Ú", "Ý", "à", "á", "â", "ã",
"è", "é", "ê", "ì", "í", "ò", "ó", "ô", "õ", "ù",
"ú", "ý", "Ă", "ă", "Đ", "đ", "Ĩ", "ĩ", "Ũ", "ũ",
"Ơ", "ơ", "Ư", "ư", "Ạ", "ạ", "Ả", "ả", "Ấ", "ấ",
"Ầ", "ầ", "Ẩ", "ẩ", "Ẫ", "ẫ", "Ậ", "ậ", "Ắ", "ắ",
"Ằ", "ằ", "Ẳ", "ẳ", "Ẵ", "ẵ", "Ặ", "ặ", "Ẹ", "ẹ",
"Ẻ", "ẻ", "Ẽ", "ẽ", "Ế", "ế", "Ề", "ề", "Ể", "ể",
# https://github.com/psf/requests/issues/2359#issuecomment-552736992
import requests
import cchardet
class ForceCchardet:
@property
def apparent_encoding(obj):
return cchardet.detect(obj.content)['encoding']
requests.Response.apparent_encoding = ForceCchardet.apparent_encoding
@sertraline
sertraline / record.sh
Created April 8, 2021 21:08
AMD FFMPEG+VAAPI screen recording with microphone input
#!/bin/bash
# AMD + FFMPEG VAAPI screen+alsa+pulseaudio recording script
# In your home directory create .asoundrc with following contents:
# pcm.!default pulse
# ctl.!default pulse
# This allows alsa to use pulseaudio as the input device.
# Bind any hotkey to the script.
# Launch once - recording starts. Launch twice - recording stops.
@sertraline
sertraline / kde_taskbar.sh
Created July 31, 2021 19:56
Remove KDE taskbar shadows
for WID in $(xwininfo -root -tree | sed '/"Plasma": ("plasmashell" "plasmashell")/!d; s/^ *\([^ ]*\) .*/\1/g'); do
xprop -id $WID -remove _KDE_NET_WM_SHADOW
done
@sertraline
sertraline / phonemask.js
Last active September 3, 2021 06:36
Pure javascript phone mask. Supports backspacing as well as selection backspacing.
export default class PhoneField {
constructor(
handler,
code = '+7',
mask = '(___)___-__-__',
placeholder = '_'
) {
this.handler = handler;
this.mask = code + mask;
this.code = code;
@sertraline
sertraline / PhoneMask.vue
Last active September 3, 2021 06:59
Vue+Vuetify phone mask w/o dependencies
<template>
<div>
<v-text-field
:ref="`input-mask-${identifier}`"
v-model="inputPhone"
outlined
dense
label="Номер телефона"
hide-details
@keydown="input"
@sertraline
sertraline / translate.js
Created November 19, 2021 07:24
Translate latin into cyrillic
const mapCyrillic = {
KeyQ: 'й',
KeyW: 'ц',
KeyE: 'у',
KeyR: 'к',
KeyT: 'е',
KeyY: 'н',
KeyU: 'г',
KeyI: 'ш',
KeyO: 'щ',
@sertraline
sertraline / Auth.py
Last active October 2, 2023 12:54
Django DRF session auth
# JWT токен не работает в SSR приложениях по типу NextJS/Sveltekit которые не могут передать на сторону сервера заголовки.
# Варианта два, передавать токен в кукисах или отказаться от токена. Это второй вариант решения
from rest_framework.decorators import api_view, authentication_classes
from rest_framework.response import Response
from rest_framework import status
from drf_yasg.utils import swagger_auto_schema
from drf_yasg import openapi
from django.contrib.auth import login
from ..serializers.Registration import RegistrationSerializer
#!/bin/bash
# Will be set to 1 by the SIGINT ignoring/postponing handler
declare -ig SIGINT_RECEIVED=0
# On <CTRL>+C or "kill -s SIGINT $$" set flag for later examination
function _set_SIGINT_RECEIVED {
SIGINT_RECEIVED=1
}
# Set to 1 if you want to keep bash running after handling SIGINT in a particular way