Skip to content

Instantly share code, notes, and snippets.

@hduffddybz
hduffddybz / client.py
Last active March 15, 2024 19:59
Python Select Server & Client
#!/usr/bin/python
import socket, select
host = '121.40.77.208'
port = 10000
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect((host, port))
inout = [socket]
@hduffddybz
hduffddybz / indefine_struct.c
Created October 29, 2014 08:55
Write indefinite length struct in C
#include <stdio.h>
struct Node
{
int data;
int length;
char buffer[0];
};
int main()
@hduffddybz
hduffddybz / function.c
Created October 30, 2014 02:09
Function pointer & Pointer function Correct Usage
#include <stdio.h>
#include <assert.h>
typedef double (*PF)(double *dbData, int iSize);
double getMin(double *dbData, int iSize)
{
double dbMin;
int i;
@hduffddybz
hduffddybz / Makefile
Last active August 29, 2015 14:08
the universal usage of Makefile
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c = .o)
CC = gcc
CCFLAGS = -g -Wall -O0
target = ringBuffer_test
$(target): $(OBJS)
$(CC) $^ -o $@ $(CCFLAGS)
%.o : %.c
@hduffddybz
hduffddybz / syslog.c
Created November 10, 2014 07:37
Usage of syslogd
#include <syslog.h>
int main()
{
setlogmask(LOG_UPTO(LOG_NOTICE));
openlog("testlog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0);
syslog(LOG_NOTICE, "LOG NOTICE");
syslog(LOG_INFO, "LOG INFO");
@hduffddybz
hduffddybz / callback.c
Created November 11, 2014 08:05
The implementation of callback function in C.
#include <stdio.h>
#include <stdlib.h>
void PrintTwoNumbers(int (*numberSource)(void))
{
printf("%d %d\n", numberSource(), numberSource());
}
int overNineThousand(void)
{
@hduffddybz
hduffddybz / net.sh
Created January 20, 2015 11:40
Traffic Monitoring on the openwrt
#!/bin/sh
#
# Traffic logging tool for OpenWRT-based routers
#
# Created by Emmanuel Brucy (e.brucy AT qut.edu.au)
#
# Based on work from Fredrik Erlandsson (erlis AT linux.nu)
# Based on traff_graph script by twist - http://wiki.openwrt.org/RrdTrafficWatch
#
# This program is free software; you can redistribute it and/or
@hduffddybz
hduffddybz / iptables.sh
Created January 22, 2015 08:49
some simple iptables.sh
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -j DROP
@hduffddybz
hduffddybz / tenth_line
Created March 31, 2015 11:06
Tenth Line
cat file.txt | sed -n 10p
@hduffddybz
hduffddybz / application
Created June 1, 2015 05:42
test case for rms
#include <rtthread.h>
#define THREAD_STACK_SIZE 512
#define THREAD_TIMESLICE 3
#define PERIOD1 25
#define PERIOD2 15
#define PERIOD3 18
#define PERIOD4 20
#define PERIOD 20
#define WCET1 4