Skip to content

Instantly share code, notes, and snippets.

View xiaozhuai's full-sized avatar

Weihang Ding xiaozhuai

  • Shanghai, China
  • 07:50 (UTC +08:00)
View GitHub Profile
@xiaozhuai
xiaozhuai / HumanReadableSize.js
Last active March 8, 2023 03:36
Get a human readabe size
function toHumanReadableSize(bytes, precision = 1) {
if (typeof bytes !== 'number' || isNaN(bytes) || !isFinite(bytes)) return '-';
const units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'BB'];
let num = bytes;
let unit = 0;
if (bytes !== 0) {
unit = Math.floor(Math.log(bytes) / Math.log(1024));
num = bytes / Math.pow(1024, Math.floor(unit));
}
if (unit === 0) {
@xiaozhuai
xiaozhuai / .clang-format
Last active May 22, 2024 11:49
My .clang-format
# You can dump builtin base style by following command
# clang-format --style=Google --dump-config > .clang-format
BasedOnStyle: 'Google'
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCompound: false
@xiaozhuai
xiaozhuai / backtrace.cpp
Created April 22, 2021 10:45
Android native c++ get back trace (stacktrace)
#include <tinyformat.h>
#include <unwind.h>
#include <cxxabi.h>
#include <dlfcn.h>
struct android_backtrace_state {
void **current;
void **end;
};
@xiaozhuai
xiaozhuai / pi_alpine_ds3231.md
Last active September 7, 2023 13:31
Raspberry pi + Alpine + ds3231

Install the RTC module on GPIO pins 1, 3, 5, 7

  1. Add or edit usercfg.txt and add
dtparam=i2c_arm=on
dtoverlay=i2c-rtc,ds3231
  1. Edit /etc/mkinitfs/mkinitfs.conf and add a feature rpirtc, then rebuild initramfs
@xiaozhuai
xiaozhuai / GL_REPEAT-and-GL_MIRRORED_REPEAT-in-shader.md
Last active July 21, 2022 04:27
Simplely implement GL_REPEAT & GL_MIRRORED_REPEAT in shader

OpenGL ES for iOS requires Power-of-Two images, unfortunately, as it is a rather strict implementation.

NPOT textures are technically enabled in the newer iOS hardware running 2.0 ES, but with extremely limited use.

Specifically, you must use linear filtering with clamp-to-edge, and no mipmapping.

And also GL_REPEAT & GL_MIRRORED_REPEAT are not supported.

In most cases a power-of-two image would still be more efficient/have higher framerates.

@xiaozhuai
xiaozhuai / fix_parallels_tools_install.md
Last active April 16, 2023 09:00
fix parallels tools install issue

install log

cd prl_fs/SharedFolders/Guest/Linux/prl_fs && make CC=cc
make[1]: Entering directory '/usr/lib/parallels-tools/kmods/prl_fs/SharedFolders/Guest/Linux/prl_fs'
make -C /lib/modules/5.0.0-25-generic/build M=/usr/lib/parallels-tools/kmods/prl_fs/SharedFolders/Guest/Linux/prl_fs CC=cc
make[2]: Entering directory '/usr/src/linux-headers-5.0.0-25-generic'
  CC [M]  /usr/lib/parallels-tools/kmods/prl_fs/SharedFolders/Guest/Linux/prl_fs/super.o
/usr/lib/parallels-tools/kmods/prl_fs/SharedFolders/Guest/Linux/prl_fs/super.c: In function 'prlfs_remount':
/usr/lib/parallels-tools/kmods/prl_fs/SharedFolders/Guest/Linux/prl_fs/super.c:119:21: error: 'MS_RDONLY' undeclared (first use in this function); did you mean 'IS_RDONLY'?
  if ( (!((*flags) & MS_RDONLY) && PRLFS_SB(sb)->readonly) ||
@xiaozhuai
xiaozhuai / TAR.bt
Last active September 13, 2021 08:21
010 editor tar template
//--------------------------------------
//--- 010 Editor v6.0.2 Binary Template
//
// File: TAR.bt
// Author: xiaozhuai
// Version: 1.0
// Purpose: Read tar files.
// Category: Archive
// File Mask: *.tar
//--------------------------------------
@xiaozhuai
xiaozhuai / php_post.php
Last active May 12, 2019 15:29
php post in 3 ways
class Request{
public static function post($url, $post_data = '', $timeout = 5){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
if($post_data != ''){
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);