Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gooooloo
gooooloo / 用写信的方式理解网络编程.markdown
Last active September 18, 2015 12:18
Understanding network programming as mail system

Understanding network programming as mail system

用写信的方式理解网络编程

2014/3/14

I have NO experience on network programming at all. Recently I learnt something, they are interesting. I am trying to summarize what I have learned as my own understanding way -- the mail system. Special thanks to Barteur Zhou.

我以前从没有过网络编程的经验和知识。最近学了一些,还挺好玩的。在这里,我想试试用自己的理解方式来总结下我近来所学的知识 -- 用写信的方式来类比。特别感谢 Barteur Zhou。

ip & port for net

package com.qidu.lin;
public class PrinterNumbers
{
/**
* 打印螺旋矩阵
0 31 30 29 28 27 26 25 24
1 32 55 54 53 52 51 50 23
2 33 56 71 70 69 68 49 22
3 34 57 72 79 78 67 48 21

HTTPS in laymen's terms

###HTTP的问题:

  • 传输过程没加密
  • 不能确保对方是正牌的服务器
  • 不能确保传输过程中没有被调包

举个例子讲就是,你要让快递把一个包裹寄给你朋友。有如下问题:

@gooooloo
gooooloo / MyLineInfo.java
Created August 19, 2016 06:46
get JAVA Line info for log.
package info.gooooloo;
public class MyLineInfo {
public static String info() {
final StackTraceElement element = new Exception().getStackTrace()[1];
return String.format("%s#%s,%s:%d",
element.getClassName(),
element.getMethodName(),
element.getFileName(),
element.getLineNumber());
public class Untitled {
public static void main(String[] args) {
final int N = 9;
int[][] a = new int[N][N];
int x = -1; int y = 0;
int dx = 0; int dy = -1;
int k = 1;
@gooooloo
gooooloo / DemoApproximateInDeepVoice.java
Last active May 4, 2017 02:37
Codes to implement the approximation of exp(x),tanh(x),sigmoid of DeepVoice paper https://arxiv.org/pdf/1702.07825.pdf
/**
* Codes to implement the approximation of compute(x) of paper https://arxiv.org/pdf/1702.07825.pdf
*/
import java.util.Random;
public class Test {
static float eTilde(float x) {
final float x2 = x * x;
final float x4 = x2 * x2;
@gooooloo
gooooloo / 距离问题模拟.py
Created May 5, 2017 07:24
模拟这个题目的过程
# 模拟这个题目的过程
# https://mp.weixin.qq.com/s?__biz=MzIzMTc0NzAwMA==&mid=2247483759&idx=1&sn=933d3522dcc197b547696ad522652b8b&key=281224a0b07438ec8edb2e3a289a23f072754ac6a4b26d9e3ce3e38cca13ec9be38b36c21c8340b80c94deb264a2ff916029a398d55725d4128d04bbbef6653083d77490729372eca7851e6b4673eac2&ascene=0&uin=MTQ0OTk4MDMwMA%3D%3D&devicetype=iMac+MacBookPro11%2C1+OSX+OSX+10.12.4+build(16E195)&version=12020510&nettype=WIFI&fontScale=100&pass_ticket=1TrgoYI6A%2Fe9EM1BEXmWAwjoNDPwfCcCsU5W1LgXMf%2BV1wgkhzYikLhX8b3Ru9op
import numpy as np
import matplotlib.pyplot as plt
def f0(xarr, a, c, d):
l = []
cyclelen = d + 1.0 * c / a
for x in xarr:
@gooooloo
gooooloo / palindromic_number.py
Created October 26, 2017 16:00
判断一个整数是不是回文数
def main(a):
a = abs(a)
b = a
c = 0
while b > 0:
c = c * 10 + b % 10
b //= 10
print(c == a)
if __name__ == '__main__':
@gooooloo
gooooloo / remove_nodes_with_val_from_linkedlist.py
Created October 26, 2017 16:24
从链表里删除指定内容的节点
class Node:
def __init__(self, v, n=None):
self.v = v
self.n = n
def do_print(head: Node):
t = head
print('=====')
while t is not None:
print(t.v)
@gooooloo
gooooloo / 打印螺旋矩阵3.py
Last active January 29, 2020 10:02
打印螺旋矩阵
def main(n):
delta = [(1,0), (0,1), (-1,0), (0,-1)]
arr = [[0 for _ in range(n)] for _ in range(n)]
row,col,k,di = -1,0,1,0
while k <= n*n:
row += delta[di][0]
col += delta[di][1]
if not 0 <= row < n or not 0 <= col < n or arr[row][col] > 0:
row -= delta[di][0]
col -= delta[di][1]