Skip to content

Instantly share code, notes, and snippets.

@jtortoise
jtortoise / Makefile
Created September 13, 2022 13:31
Wireshark PCAP file format splitting file size demo
O_DIR := build
CREATE_O_DIR := $(shell mkdir -p $(O_DIR))
BIN := $(O_DIR)/main
SRCS := $(wildcard *.cpp)
temp_OBJS := $(addsuffix .o,$(basename $(SRCS)))
OBJS := $(temp_OBJS:%=$(O_DIR)/%)
temp_DEPENDS := $(addsuffix .d,$(basename $(SRCS)))
@jtortoise
jtortoise / Makefile
Created August 13, 2022 13:15
A simple Makefile template for C/C++ project
O_DIR := build
CREATE_O_DIR := $(shell mkdir -p $(O_DIR))
BIN := $(O_DIR)/main
SRCS := $(wildcard *.cpp)
temp_OBJS := $(addsuffix .o,$(basename $(SRCS)))
OBJS := $(temp_OBJS:%=$(O_DIR)/%)
temp_DEPENDS := $(addsuffix .d,$(basename $(SRCS)))
@jtortoise
jtortoise / Makefile
Created July 30, 2022 12:58
Ring buffer save as wireshark pcap file demo
O_DIR := build
CREATE_O_DIR := $(shell mkdir -p $(O_DIR))
BIN := $(O_DIR)/main
SRCS := $(wildcard *.cpp)
temp_OBJS := $(addsuffix .o,$(basename $(SRCS)))
OBJS := $(temp_OBJS:%=$(O_DIR)/%)
temp_DEPENDS := $(addsuffix .d,$(basename $(SRCS)))
@jtortoise
jtortoise / icmp_demo.c
Created November 9, 2018 02:36
socekt icmp demo
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <strings.h>
#include <errno.h>
#include <sys/socket.h>
#include <resolv.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip_icmp.h>
@jtortoise
jtortoise / main.cpp
Last active March 9, 2022 10:18
Json format for Qt's QSettings class. Doesn't support json array
#include <QCoreApplication>
#include <QtCore>
#include "qsettings_json.hpp"
int main(int argc, char *argv[])
{
QSettings setting("config.json", JsonFormat);
qDebug().noquote() << setting.value("data").toInt();

git status 中文编码问题

输入下面命令配置git工具:

git config --global core.quotepath false 
@jtortoise
jtortoise / CMakeLists.txt
Last active March 21, 2018 14:27
自动包含子目录的CMakeLists.txt脚本,不支持递归包含
MACRO(auto_add_subdir cur_dir)
#ignore idea project configure dir
file(GLOB children RELATIVE ${cur_dir} [^.]*)
#set(dirlist "")
foreach(child ${children})
#sure it is dir and has cmakelist.txt file
if(IS_DIRECTORY ${cur_dir}/${child} AND EXISTS ${cur_dir}/${child}/CMakeLists.txt)
#list(APPEND dirlist ${child})
add_subdirectory(${child})
endif()
@jtortoise
jtortoise / example.c
Created February 8, 2018 12:50
C官方库虽然没有提供map库,但第三方库还是有一些挺不错的,用了几个后发现这些hashmap库对内存有一些要求,而针对STM32这种MCU,内存是最珍贵的资源了,基本都满足不了这些库的要求,就只能自己动手写一个简单粗暴的hashmap库满足自己的需求。
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "hashmap.h"
int main(void)
{
int val[5] = {0, 1, 2, 3, 4};
hashmap* map = HashmapInit(5);
@jtortoise
jtortoise / fsm.c
Created February 4, 2018 06:35 — forked from ankurs/fsm.c
FSM in C
/**
* @file fsm.c
* @brief an implementation for a FSM in C, this file contains
* implementation of definations.
* License GPLv3+
* @author Ankur Shrivastava
*/
#include "fsm.h"
#include<stdlib.h>