Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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;
@rickyzhang-cn
rickyzhang-cn / lis.cpp
Created May 8, 2015 07:12
Longest Increasing Subsequence
#include <iostream>
using namespace std;
int lis(int A[], int n){
int *d = new int[n];
int len = 1;
for(int i=0; i<n; ++i){
d[i] = 1;
for(int j=0; j<i; ++j)
if(A[j]<=A[i] && d[j]+1>d[i])
@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 / skiplist.c
Created April 27, 2015 12:02
skiplist的一个C实现
/* ======================================================================
* Copyright (c) 2000,2006 Theo Schlossnagle
* All rights reserved.
* The following code was written by Theo Schlossnagle for use in the
* Backhand project at The Center for Networking and Distributed Systems
* at The Johns Hopkins University.
*
* This is a skiplist implementation to be used for abstract structures
* and is release under the LGPL license version 2.1 or later. A copy
* of this license can be found file LGPL.
@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. *