This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tested on cpython v3.9.5 | |
import http.client | |
import json | |
import pathlib | |
import socket | |
class _HttpConnectionUnixSocket(http.client.HTTPConnection): | |
def __init__(self, path: pathlib.Path) -> None: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e # Exit on error | |
DEVICE=$1 | |
[ -z "${DEVICE}" ] && echo "Usage $0 /dev/sdX" && exit 1 | |
udevadm info -n ${DEVICE} -q property | |
echo "Selected device is ${DEVICE}" | |
read -p "[Press enter to continue or CTRL+C to stop]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://forum.pine64.org/showthread.php?tid=1297&pid=15958#pid15958 | |
$ fdtget --type x /boot/pine64/sun50i-a64-pine64-plus.dtb /soc@01c00000/eth@01c30000 reg | |
0 1c30000 0 10000 0 1c00000 0 30 | |
# https://forum.pine64.org/showthread.php?tid=1297&pid=16138#pid16138 | |
$ fdtget /boot/pine64/sun50i-a64-pine64-plus.dtb /aliases spi0 | |
/soc@01c00000/spi@01c68000 | |
$ fdtget /boot/pine64/sun50i-a64-pine64-plus.dtb /soc@01c00000/spi@01c68000 status | |
disabled | |
$ sudo fdtput --verbose --type s /boot/pine64/sun50i-a64-pine64-plus.dtb /soc@01c00000/spi@01c68000 status okay |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import select | |
DEFAULT_BUFFER_SIZE_BYTES = 8196 | |
DEFAULT_READ_TIMEOUT_SECONDS = 1.0 | |
def rselect(fd, timeout_seconds=None): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
> sstream = io.StringIO() | |
> subprocess.run(['hostname'], stdout=sstream, check=True) | |
io.UnsupportedOperation: fileno | |
""" | |
import os | |
import select |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <security/pam_appl.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> // getpass | |
// apt install libpam0g-dev | |
// compile with flag -lpam |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -lgcrypt ... | |
#include <assert.h> | |
#include <gcrypt.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
const size_t KEYGRIP_LENGTH = 20; | |
unsigned char* read_binary(const char* path, size_t* bytes_read) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Display names of outputs available to the X server similiar to 'xrandr' command. | |
Access xlib and xrandr extension via python's ctypes library. | |
tags: x11, xorg, x.org, xwindow-system, xlib, libx, xrandr, outputs, monitor, display | |
""" | |
import ctypes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
python-xlib's Xlib.display.next_event() does not have a timeout when waiting for an event to be queued. | |
It may block the script's execution forever. | |
Workaround: | |
Call display.next_event() only if an event is available in the queue. | |
Use select.select() on the xserver's socket to wait for an event and specify a timeout. | |
based on: https://stackoverflow.com/a/8592969/5894777 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use \Sabre\HTTP\RequestInterface; | |
use \Sabre\HTTP\ResponseInterface; | |
class SabreDavYii2AuthBackend implements \Sabre\DAV\Auth\Backend\BackendInterface | |
{ | |
function check(RequestInterface $request, ResponseInterface $response) | |
{ | |
if(\Yii::$app->user->isGuest) { |
NewerOlder