Skip to content

Instantly share code, notes, and snippets.

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

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

View httpsInLaymensTerms.markdown

HTTPS in laymen's terms

###HTTP的问题:

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

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

@gooooloo
gooooloo / MyLineInfo.java
Created Aug 19, 2016
get JAVA Line info for log.
View MyLineInfo.java
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());
View 打印螺旋矩阵2
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
Codes to implement the approximation of exp(x),tanh(x),sigmoid of DeepVoice paper https://arxiv.org/pdf/1702.07825.pdf
View DemoApproximateInDeepVoice.java
/**
* 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
模拟这个题目的过程
View 距离问题模拟.py
# 模拟这个题目的过程
# 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 Oct 26, 2017
判断一个整数是不是回文数
View palindromic_number.py
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 Oct 26, 2017
从链表里删除指定内容的节点
View remove_nodes_with_val_from_linkedlist.py
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 / 2018年刑侦科目推理试题.py
Last active Mar 2, 2018
2018年刑侦科目推理试题
View 2018年刑侦科目推理试题.py
# http://news.sina.com.cn/s/wh/2018-03-02/doc-ifyrztfz6281140.shtml
def main():
ans = [None for _ in range(10+1)]
def least_answered(ans):
vs = ans[1:]
vc = {v:vs.count(v) for v in vs}
minc = min(vc.values())
for v,c in vc.items():
View 打印螺旋矩阵.java
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