Skip to content

Instantly share code, notes, and snippets.

@rickyzhang-cn
rickyzhang-cn / rngLib.c
Created November 7, 2014 12:03
VxWorks下rngLib的实现代码
/* rngLib.c - ring buffer subroutine library */
/* Copyright 1984-1995 Wind River Systems, Inc. */
/*
modification history
--------------------
01x,13feb95,jdi doc tweaks.
01w,20jan93,jdi documentation cleanup for 5.1.
@rickyzhang-cn
rickyzhang-cn / main.c
Created January 6, 2015 12:44
Reactor模式示例代码
#include <arpa/inet.h>
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <sys/types.h>
#include <pthread.h>
@rickyzhang-cn
rickyzhang-cn / Makefile
Last active June 25, 2022 03:33
openssl demo
INC=/usr/local/ssl/include/
LIB=/usr/local/ssl/lib/
all:
g++ -I$(INC) -L$(LIB) cli.cpp -o cli -lssl -lcrypto -ldl -fpermissive
g++ -I$(INC) -L$(LIB) serv.cpp -o serv -lssl -lcrypto -ldl -fpermissive
clean:
rm -rf *~ cli serv
@rickyzhang-cn
rickyzhang-cn / simple_lru.cpp
Created May 8, 2015 02:12
A simple lru implementation with c++
// A simple LRU cache written in C++
// Hash map + doubly linked list
#include <iostream>
#include <vector>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
template <class K, class T>
struct Node{
@rickyzhang-cn
rickyzhang-cn / simpletun.c
Created April 27, 2015 09:08
一个简单的使用tun/tap建立tunnel的示例代码
/**************************************************************************
* simpletun.c *
* *
* A simplistic, simple-minded, naive tunnelling program using tun/tap *
* interfaces and TCP. Handles (badly) IPv4 for tun, ARP and IPv4 for *
* tap. DO NOT USE THIS PROGRAM FOR SERIOUS PURPOSES. *
* *
* You have been warned. *
* *
* (C) 2009 Davide Brini. *
@rickyzhang-cn
rickyzhang-cn / # python - 2018-11-05_20-05-36.txt
Created November 8, 2018 11:55
python on macOS 10.14 - Homebrew build logs
Homebrew build logs for python on macOS 10.14
Build date: 2018-11-05 20:05:36
@rickyzhang-cn
rickyzhang-cn / solution.cpp
Created March 9, 2016 09:01
interview solution
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cctype>
using namespace std;
bool Substitude(const string &template_str, map<string,string> &mapping, string &output) {
int state=0;
@rickyzhang-cn
rickyzhang-cn / minivpn.c
Created June 2, 2015 08:36
miniVPN based on OpenSSL and TUN/TAP
/*
* tunproxy.c --- small demo program for tunneling over UDP with tun/tap
*
* Copyright (C) 2003 Philippe Biondi <phil@secdev.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
@rickyzhang-cn
rickyzhang-cn / itimer_demo.c
Last active August 29, 2015 14:22
timerfd demo
//gcc -o itimer_demo itimer_demo.c -lrt
#include <sys/timerfd.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h> /* Definition of uint64_t */
#define handle_error(msg) \
@rickyzhang-cn
rickyzhang-cn / ReferenceCounting.cpp
Created May 15, 2015 07:34
Reference count, copy-on-write
//: C12:ReferenceCounting.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Reference count, copy-on-write
#include "../require.h"
#include <string>
#include <iostream>
using namespace std;