Skip to content

Instantly share code, notes, and snippets.

View k3a's full-sized avatar

K3A k3a

  • K3A & Ndemic Creations
  • Czech Republic
View GitHub Profile
@k3a
k3a / fixphp.rb
Created April 23, 2022 19:12
A tiny Ruby tool to change <? to <?php in each file inside a specified directory including sub-directories
Raw
Blame
#!/usr/bin/env ruby
# PHP file tag fixer by K3A.me
# Changes <? to <?php in each file
abort("Usage: fixphp.rb <path_to_a_folder>") if ARGV.length == 0
@k3a
k3a / psd2pcap.py
Created March 6, 2022 20:14
Zigbee .psd to .pcap conversion
#!/usr/bin/env python3
# Converts SmartRF Zigbee Sniffer .psd format into .pcap using Scapy
# Can be used with Texas Instruments, Inc. CC2531 Dongle
#
# Author: k3a.me
# License: MIT
#
# TIP: On Linux, you can use https://github.com/homewsn/whsniff
# to directly communicate with the dongle and produce pcap
@k3a
k3a / PKGBUILD
Created June 2, 2021 14:55
basez aur package
# Maintainer: MasterDocNoble <MasterDocNoble@protonmail.com>
pkgname=basez
pkgver=1.6.2
pkgrel=2
pkgdesc='base 16/32/64 encode/decode data to standard output'
arch=('x86_64')
url='http://www.quarkline.net/basez/'
depends=('gcc-libs')
license=('GPL3' 'BSD' 'CCPL')
[117591.900149] scsi 0:0:2:0: Direct-Access Google PersistentDisk 1 PQ: 0 ANSI: 6
[117591.913777] sd 0:0:2:0: [sdb] 16777216 512-byte logical blocks: (8.59 GB/8.00 GiB)
[117591.922085] sd 0:0:2:0: [sdb] 4096-byte physical blocks
[117591.939572] sd 0:0:2:0: [sdb] Write Protect is off
[117591.945231] sd 0:0:2:0: [sdb] Mode Sense: 1f 00 00 08
[117591.951895] sd 0:0:2:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[117592.008681] sd 0:0:2:0: [sdb] Attached SCSI disk
[117596.992703] EXT4-fs (sdb): VFS: Can't find ext4 filesystem
[117599.176431] EXT4-fs (sdb): mounted filesystem with ordered data mode. Opts: (null)
[180881.413099] bash (80140): drop_caches: 3
#!/bin/sh
#FLAGS="-hide_banner -loglevel error "
FLAGS="-hide_banner -loglevel warning "
echo === 128 AMD ====
vainfo --display drm --device /dev/dri/renderD128 | head -n3
# produces 5240 kb/s on Linux 5.2.9 ffmpeg-4.2-4 libva-mesa-driver-19.1.5-1 (3.9.2019)
time ffmpeg $FLAGS -vaapi_device /dev/dri/renderD128 -i big_buck_bunny_720p_1mb.mp4 -vf 'format=nv12,hwupload' -c:v hevc_vaapi -b:v 5M -y new_bunny_128.mp4
#include <stdio.h> // definition of printf()
#include <stdint.h> // definitions of uint32_t and other types
void printUInt(uint32_t val) {
unsigned char binval[33];
for (unsigned i=0; i<32; i++) {
binval[i] = (val & (1<<(31-i))) ? '1' : '0';
}

W3C pointer events

https://www.w3.org/TR/pointerevents/ - A good source of inspiration I discovered during my pointer implementation research. It actually maps well to my platform-specific findings described bellow.

Mouse and touch events have been here for historical and/or compatibility reasons and nowadays it makes more sense to implement more generic Pointer Events which can represent all three main input sources.

Mouse/touch/pointer handling in other frameworks

Touch

#!/usr/bin/env python3
#
# Test script to convert between xtilt/ytilt (Qt, Windows) and azimuth/altitude (iOS)
# Free to use for any purpose
import math
import secrets
# [azimuthRad, altitudeRad] => [tiltXrad, tiltYrad]
# azimuth in [0, 2*pi] range, altitude in [0, pi/2]
@k3a
k3a / captest.c
Created April 25, 2019 16:28
Example code using libcap to set CAP_NET_BIND_SERVICE (binding to port 81) to the effective capability set.
/*
Example code using libcap to set CAP_NET_BIND_SERVICE
(binding to port 81) to the effective capability set.
For more info, see the full blog post at
https://k3a.me/linux-capabilities-in-a-nutshell/
*/
#include <stdlib.h>
#include <stdio.h>

Keybase proof

I hereby claim:

  • I am k3a on github.
  • I am k3a (https://keybase.io/k3a) on keybase.
  • I have a public key whose fingerprint is 6785 1870 D0DF 60B0 E56D A87F 036C 1F00 FE65 B108

To claim this, I am signing this object: