Friday, January 11, 2019

01-10-2019

Udemy Web Developer Bootcamp Section4 finished.
form, input, label etc.



Wednesday, January 9, 2019

01-09-2019

农历生日

路上看microservices

看Core Java I 11th edition
Read about 11 buzzwords (Chapter 1.2)
Chapter 1
1.2 11 buzzwords

  1. Simple
  2. Object-Oriented
  3. Distributed
  4. Robust
  5. Secure
  6. Arcitecture-Neutral (JVM, Java runtime system)
  7. Portable (size of primitive dat types are specified, for example int is always 32bit.)
  8. Interpreted (jshell in Java 9 for rapid and exploratory programming)
  9. High-Performance (just-in-time compilers)
  10. Multithreaded (use more processors in parallel)
  11. Dynamic
1.3 Java applets and the Internet
    applets: Java programs that work on web pages (need a supporting browser)
But actually Flash became popular.
Nowadays usually can use HTML and Javascript

打表学习从2019.1.10开始

用小本本记下来每天做了什么,学到了什么。

Thursday, May 17, 2018

读1997年写雷军的文章有感

里面有一些雷军的讲话很有道理,值得学习。
摘录几条在下面自己经常看看。

1. 计算机搞懂精髓以后,所有的东西都很简单。计算机不是一门理论性很强的学科,强调的是实践。

2. 雷军的工作任务是按半小时来定的,当时雷军有一个笔记本记着每半小时干了什么。“如果浪费了半小时时间,我就觉得很惭愧。后来我看到很多人不珍惜时间的时候,我就觉得这样的人真没出息。时间是自己的,你到一个公司打工的时候,偷懒,老板没有看见,就觉得自己又蒙了一下,玩猫和老鼠的游戏,真是没有必要。公司所付的那么一点钱,就买下了你一个月的青春?学会的东西首先是自己的,其次才是公司的。没有多少人真正计算过自己一个小时值多少钱。”

3. 最让雷军佩服的程序员是现在中文之星的核心程序员陈波。“他写程序全是在上班时间,他每天按时上班按时下班,从不加班,但上班时间他时间利用率很高,连水都不喝,女朋友的电话都是中午去接。像这样的人就是为写程序而生的,就像李昌镐是为下棋而生的一样。”

4. 雷军承认自己写程序不如陈波。“我有杂念,而真正第一流的程序员是没有杂念的。我曾经72小时不睡觉连续写程序,但这有什么了不起呢?别人也可以三天三夜在麻将桌上不下来,难的是早上8点钟开始打牌,打到12点,下午1点再开始打,打到下午5点,这样一直坚持一年。”

5. 写了这么多年程序,雷军感触最深的有两点:第一,程序不仅仅是核心程序员的,同时也应该是用户和同事参与完成的,所以,功劳应该属于大家,不能把光环套在一个人头上;第二,程序员要有方便别人,麻烦自己的精神。因为,程序员花两天改进的一个小模块,就有可能会省却了用户数以百万计的麻烦。雷军最烦听到有程序员对他讲,程序改起来太麻烦,这个小错误凑合算了的话。“程序员发现自己的程序中有一个小小bug没有改,就应该睡不着觉。”

6. 在雷军看来,公司里面一个人干一个半人的工作最理想。“一个人干一个人工作的公司是不行的,在这么激烈的竞争中,无法降低成本;一个人干两个人的工作,人员没有任何冗余,任何一个人走,都会对公司结构造成致命的损失,组织不能够安全运行。”

另外从文章里看到,雷军是一个很能表达的人,不光是说,而且文章也写的好。所以可以看出,交流,表达能力是非常非常重要的。

Wednesday, April 5, 2017

Tuesday, January 31, 2017

K closest points

Find the K closest points to the origin in a 2D plane, given an array containing N points.

 Method1, use a priority queue. Because it takes constant time to retrieve the smallest one always.
/*
public class Point {
    public int x;
    public int y;
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}
*/
 
public List<Point> findKClosest(Point[] p, int k) {
    PriorityQueue<Point> pq = new PriorityQueue<>(10, new Comparator<Point>() {
        @Override
        public int compare(Point a, Point b) {
            return (b.x * b.x + b.y * b.y) - (a.x * a.x + a.y * a.y);
        }
    });
     
    for (int i = 0; i < p.length; i++) {
        if (i < k)
            pq.offer(p[i]);
        else {
            Point temp = pq.peek();
            if ((p[i].x * p[i].x + p[i].y * p[i].y) - (temp.x * temp.x + temp.y * temp.y) < 0) {
                pq.poll();
                pq.offer(p[i]);
            }
        }
    }
     
    List<Point> x = new ArrayList<>();
    while (!pq.isEmpty())
        x.add(pq.poll());
     
    return x;
}

Max points on a line

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

public int maxPoints(Point[] points) {
    if(points == null || points.length == 0) return 0;
 
    HashMap<Double, Integer> result = new HashMap<Double, Integer>();
    int max=0;
 
    for(int i=0; i<points.length; i++){
        int duplicate = 1;//
        int vertical = 0;
        for(int j=i+1; j < points.length; j++){
            //handle duplicates and vertical
            if(points[i].x == points[j].x){
                if(points[i].y == points[j].y){
                    duplicate++;
                }else{
                    vertical++;
                }
            }else{
                double slope = points[j].y == points[i].y ? 0.0
            : (1.0 * (points[j].y - points[i].y))
      / (points[j].x - points[i].x);
 
                if(result.get(slope) != null){
                    result.put(slope, result.get(slope) + 1);
                }else{
                    result.put(slope, 1);
                }
            }
        }
 
        for(Integer count: result.values()){
            if(count+duplicate > max){
                max = count+duplicate;
            }
        }
 
        max = Math.max(vertical + duplicate, max);
        result.clear();
    }
 
 
    return max;
}