Skip to content

Instantly share code, notes, and snippets.

View z4yx's full-sized avatar
☢️

Yuxiang Zhang z4yx

☢️
View GitHub Profile
l = ['B7','B6','E20','B5','B3','B2','C3','C0','C1','E22','G0','G2','G4','G5','G3','G1','E21','C2','B0','B1','B4']
n = []
path = '/sys/class/gpio'
for io in l:
num = ord(io[0])-ord('A')
num = num*32+int(io[1:])
n.append(num)
for num in n:
print('echo %d >%s/export'%(num,path))
print('echo out >%s/gpio%d/direction'%(path,num))
@z4yx
z4yx / wiper.sh
Created May 20, 2020 08:56
ketanarlulkar/hdparm
#!/bin/bash
#
# SATA SSD free-space TRIM utility, by Mark Lord <mlord@pobox.com>
VERSION=3.6
# Copyright (C) 2009-2010 Mark Lord. All rights reserved.
#
# Contains hfsplus and ntfs code contributed by Heiko Wegeler <heiko.wegeler@googlemail.com>.
# Package sleuthkit version >=3.1.1 is required for HFS+. Package ntfs-3g and ntfsprogs is required for NTFS.
import sys
import subprocess
import notify2
import dbus
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
import yubico
def check(bus, msg):
if msg.get_path() != "/ScreenSaver":
return
echo "" >>/media/removable/boot/config.txt
echo "enable_uart=1" >>/media/removable/boot/config.txt
touch /media/removable/boot/ssh
cat >/media/removable/boot/wpa_supplicant.conf <<EOF
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="dd-wrt"
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __BPF_HELPERS_H
#define __BPF_HELPERS_H
/* helper macro to place programs, maps, license in
* different sections in elf_bpf file. Section names
* are interpreted by elf_bpf loader
*/
#define SEC(NAME) __attribute__((section(NAME), used))
@z4yx
z4yx / rhel-nginx-module.md
Last active March 12, 2020 12:03
如何为rhel编译nginx module (how to compile dynamic nginx modules on rhel)

下载源码

wget 'http://nginx.org/packages/centos/7/SRPMS/nginx-1.14.2-1.el7_4.ngx.src.rpm'
rpm -i nginx-1.14.2-1.el7_4.ngx.src.rpm
tar -xf rpmbuild/SOURCES/nginx-1.14.2.tar.gz

下载module源码

From 84a933323d59b27ae85cf16deddc254a0b17e450 Mon Sep 17 00:00:00 2001
From: Shraddha Chaudhari <Shraddha.Chaudhari@imgtec.com>
Date: Tue, 5 Jan 2016 11:16:43 +0530
Subject: mtd: spi-nor: add support for winbond OTP
Few winbond spi nor devices support 3 x 256 bytes
of security registers, add support for read, write, lock
of these registers as user OTP.
Also add support for reading winbond devices unique ID
@z4yx
z4yx / W25Q128-ID.c
Created March 8, 2020 12:23
kernel driver code snippet to read unique ID of W25Q128
#include <linux/random.h>
int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) {
// ...
// after mutex_init(&nor->lock);
if(memcmp(info->id, "\xef\x40\x18", 3) == 0) {
int ret;
u8 buf[4+8]; // 4 dummy + 64-bit ID
dev_warn(dev, "reading unique ID\n");
ret = nor->read_reg(nor, 0x4B, buf, sizeof(buf)); // Read Unique ID number
package main
// bash -c 'CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o clean clean.go'
// Usage:
// bandersnatch -c /tmp/b.conf verify --delete --dry-run &>verify-dry-run.log
// ./clean <verify-dry-run.log >clean.log
import ( "fmt";"log"; "os"; "time";"bufio";"strings" )
func main() {
@z4yx
z4yx / mipsel-none-elf-binutils.rb
Created January 18, 2020 13:57
MIPS GCC for Homebrew
class MipselNoneElfBinutils < Formula
desc "FSF Binutils for mipsel cross development"
homepage "https://www.gnu.org/software/binutils/"
url "https://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.gz"
sha256 "9b0d97b3d30df184d302bced12f976aa1e5fbf4b0be696cdebc6cca30411a46e"
def install
system "./configure", "--target=mipsel-none-elf",
"--disable-multilib",
"--disable-nls",