Skip to content

Instantly share code, notes, and snippets.

View guiyanzhong's full-sized avatar

guiyanzhong guiyanzhong

View GitHub Profile
@guiyanzhong
guiyanzhong / modbus_rs232_master_client.c
Created November 29, 2023 02:55 — forked from JGrossholtz/modbus_rs232_master_client.c
A sample libmodbus client / server (master/slave) using RS232 to request data from a modbus client (tested with libmodbus3.0.6)
#include <stdio.h>
#include <unistd.h>
#include <modbus.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/serial.h>
#include <asm/ioctls.h>
#define NB_REGS 2

Elixir Best Practices: When to Use Structs, String-keyed Maps, and Atom-keyed Maps

  • Rule #1: Always Use String-Keyed Maps for External Data
  • Rule #2: Convert External Data to Structs ASAP
  • Rule #3: Use Structs in All Other Code
  • Rule #4: Use Structs for Output Data
  • Rule #5: Avoid Using Atom-keyed Maps That Aren’t Structs
  • Rule #6: Use Keyword Lists Only for Function Arguments
@guiyanzhong
guiyanzhong / overlapPercent.cpp
Created August 29, 2020 07:42 — forked from MareArts/overlapPercent.cpp
openCV Tip, Calculate overlap percent between two rectangle.
http://study.marearts.com/2017/09/opencv-tip-calculate-overlap-percent.html
Mat canvas(100, 100, CV_8UC3);
canvas.setTo(0);
Rect rectA(10, 5, 50, 60);
Rect rectB(40,40,30, 40);
Rect andRect_overlap = (rectA & rectB);
Rect orRect_whole = (rectA | rectB);
cout << "rect A info. : " << rectA << endl;
@guiyanzhong
guiyanzhong / ssl.cpp
Created July 2, 2020 02:39 — forked from cseelye/ssl.cpp
Get SSL certificate info using openssl from C++
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>
#include <openssl/asn1.h>
#include <openssl/bio.h>
#include <openssl/conf.h>
#include <openssl/err.h>
#include <openssl/pem.h>
@guiyanzhong
guiyanzhong / vlcsms.c
Created March 4, 2019 07:56 — forked from TimSC/vlcsms.c
Using libvlc to extract raw frames and audio from media via smem
//To compile:
//cc vlcsms.c -o vlcsms -lvlc
//This source is by Tim Sheerman-Chase and it is released as public domain.
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <vlc/vlc.h>
@guiyanzhong
guiyanzhong / .vimrc
Created July 27, 2016 05:39 — forked from jhezjkp/.vimrc
vim配置
"安装/更新:BundleInstall
"卸载即将对应项注释后再运行:BundleClean
"取消兼容模式
set nocompatible
"关闭文件类型侦测,必须
filetype off
"powerline配置要求
set laststatus=2
"编码设置
@guiyanzhong
guiyanzhong / 2048.c
Created June 30, 2016 08:27 — forked from justecorruptio/2048.c
Tiny 2048 in C!
M[16],X=16,W,k;main(){T(system("stty cbreak")
);puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i
,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M
[w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<<
(l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k)
]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d
-1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X]
*i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4;
)s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4||
puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2