Skip to content

Instantly share code, notes, and snippets.

View panqiincs's full-sized avatar

panqiincs

View GitHub Profile
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@panqiincs
panqiincs / image_send.cpp
Last active April 22, 2022 15:07
Read image data from rpi camera, compress image data and send.
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
@panqiincs
panqiincs / bin_split.py
Last active October 4, 2020 13:06
Binary file padding and splitting.
#!/usr/bin/env python3
import os
import sys
import time
def doThings(file_name="./sample.jpg", stm32_bufsize=32768, rpi_bufsize=4096, interval=0.0):
file_size = os.path.getsize(file_name)
print(f"### Original file size: {file_size} bytes.")
@panqiincs
panqiincs / nginx_log_filter.py
Last active April 26, 2019 05:15
Nginx log filter
#!/usr/bin/python3
import sys
import re
# ADDRESS filter
def addr_filter(addr):
# Omit some addresses
ips = (re.search(r"^117.140.3", addr) != None) or \
(re.search(r"^45.77.182.191", addr) != None)
@panqiincs
panqiincs / client_fork.c
Last active January 13, 2019 07:22
A client using fork
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <arpa/inet.h>
@panqiincs
panqiincs / echo_server_fork.c
Last active January 13, 2019 07:22
A concurrent echo server using fork
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <arpa/inet.h>
@panqiincs
panqiincs / echo_server_iter.c
Last active January 13, 2019 07:22
A iterative echo server.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
void error(char *msg) {
perror(msg);
exit(EXIT_FAILURE);
@panqiincs
panqiincs / echo_server_select.c
Last active August 26, 2018 02:57
An echo server using select
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <errno.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
@panqiincs
panqiincs / psh.c
Created August 6, 2018 05:26
A Shell program with basic functionality.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#define MAX_ARG_NUM 20 // max number of arguments
#define MAX_ARG_LEN 200 // max length of commands