Skip to content

Instantly share code, notes, and snippets.

@LihuaWu
LihuaWu / socket.cc
Last active July 12, 2019 12:17
socket.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <errno.h>
@LihuaWu
LihuaWu / The Technical Interview Cheat Sheet.md
Created May 31, 2016 09:28 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@LihuaWu
LihuaWu / rvalue_reference.cc
Created March 31, 2016 03:09
what is exactly a rvalue reference in cpp?
#include <utility>
#include <iostream>
int main() {
int a = 5;
int&& b = std::move(a); //我觉得5-6行本就不应该编译过,b的类型是右值引用,但是b出现在表达式的左边,因此是个左值。这是为啥呢?
b++;
std::cout << "a is : " << a << "\n";
return 0;
}
#include <iostream>
#include <utility>
#include <memory>
using namespace std;
int main() {
std::unique_ptr<int> upi(new int(5));
//
// Simple and fast atof (ascii to float) function.
//
// - Executes about 5x faster than standard MSCRT library atof().
// - An attractive alternative if the number of calls is in the millions.
// - Assumes input is a proper integer, fraction, or scientific format.
// - Matches library atof() to 15 digits (except at extreme exponents).
// - Follows atof() precedent of essentially no error checking.
//
// 09-May-2009 Tom Van Baak (tvb) www.LeapSecond.com
#include <stdio.h>
#include <functional>
#include <iostream>
using namespace std;
namespace UseConstAndNonConstLvalueRef {
void F(int&& a) {
printf("rvalue ref: %d\n", a);
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <memory>
#include <utility>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
int abs(int x) {
return x > 0 ? x : -x;