Skip to content

Instantly share code, notes, and snippets.

View tolinwei's full-sized avatar

Wei Lin tolinwei

  • Facebook
  • Cambridge, MA
View GitHub Profile
@tolinwei
tolinwei / MyRoutingProto.java
Last active December 16, 2015 16:39
The 4th assignment of Computer Network: My Routing Protocol
import java.net.*;
//net.InetAddress;
//net.DatagramPacket;
//net.DatagramSocket;
import java.util.*;
import java.io.*;
//io.File;
class Receiving extends Thread {
//constructor
@tolinwei
tolinwei / WebServer.java
Last active December 16, 2015 16:39
The 1st assignment of Computer Network: Java Web Server
import java.net.*;
import java.util.*; //for ArrayList and Date
import java.io.*;
class ConnectionThread extends Thread {
Socket client; //class member
int counter; //class member
//constructor
public ConnectionThread(Socket cl, int c) {
client = cl;
@tolinwei
tolinwei / taxi.py
Last active December 17, 2015 05:39
import math
# Read file
input = open("input.txt")
rows = []
for line in input.readlines():
rows.append(line[0: -1])
input.close()
# for row in rows:
from flask import Flask
from flask import request
app = Flask(__name__)
#Normally this would be an external file like object, but here
#it's inlined
FORM_PAGE = """
<html>
<head>
<title>Flask Form</title>
#include <iostream>
#include <stack>
using namespace std;
class MyStack
{
private:
stack<int> s;
stack<int> min;
public:
void push(int v) {
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
void two_sum(int array[], int sum)
{
unordered_set<int> us;
vector<int> v (array, array+7);
for (int i = 0; i < v.size(); i++) {
if (us.find(sum - array[i]) == us.end()) {
#include <iostream>
#include <stack>
using namespace std;
class MyQueue
{
private:
stack<int> in;
stack<int> out;
public:
void push(int v) {
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
class SetOfStacks //stacks managed by vector
{
private:
int capacity;
vector<stack<int>> vs;
#include <iostream>
#include <stack>
using namespace std;
/*
s:
2
8
9
3
#include <iostream>
#include <stack>
using namespace std;
class Node
{
public:
int value;
Node *next;
Node(int v) : value(v) {}
};