Quick solution for lagging in Chrome with Nvidia Hackintosh
2018-02-03

> Introduction

For those of you love simplicity and complexity that Chrome provides, and also running a Hackintosh with Nvidia drivers, you might notice it’s super lagging when browsing or even just open your Chrome.

Note: The version I’m running: Chrome 64.0.3282.140, MacOs 10.13.3

I’m not if it’s Nvidia’s fault or Apple’s, but it seems like they have a terrible partnership. So, unless you try to buy a AMD GPU, I suppose you would like to disable you hardware acceleration in Google Chrome. I feel like my Chrome has revived after all the suffer.

Hexo embeded with tags (Youtube, Twitter, Instagram)
2018-01-27

> Embed web pages in your post

Recently, I found Hugo, which is another static site generator, comes with some useful shortcodes that allows you embed html figure, instagram, speakerdeck, youtube, twitter and so on in your post. That’s a great feature for some social guys.

And of course, we can do this in hexo with some plugins.

Thanks god. I don’t even play Instagram, twitter. And my youtube channel is just full with school stuff. What a boring man am I.😂😂😂 So I just put other people’s nice one here as examples.

Get your imenu ready for modern Javascript
2017-12-29

> Introduction

These days, I was working on a React Native project. In the meanwhile, I found it’s kind of hard to catch up the modern syntax of Javascript, so as for imenu (a built in project structure menu bar in Emacs).

Fortunately, there are so many people love Emacs and contribute to it. Thanks for Chen bin’s great post. I just put down more imenu generic expressions for modern Javascript like React, Vue. This helps me navigate and go through projects.

Spacemacs/Space-Vim Config for VSCode
2017-12-02

> The space way

> Leader key

Using space key as the leader is a very popular way of editing, navigation and commanding. There is never an easy way to get used to new shortcuts, but trust me, you would definitely like it once you use it.

> Sticky key

Think about how you invoke commands in VSCode before. When you want to call the command-palette, you need to put your left hand’s two fingers on Ctrl + Shift key or Command + Shift key and press p. And note that it’s a key chord combination when you actually press these keys.

This looks so stupid when you compare it with just Space Space in Vim’s normal or visual mode. And by saying Space Space, it’s a sticky key bindings which means you just type space key twice in sequence. And you can just set your hands as the default typing position shown in this picture.

Game theory: Solutions for others
2017-09-09

This post contains solutions for other game theory problems.

Again, I don’t have much time putting down a lot of details here…

> Flip game II

  • Problem:

https://leetcode.com/problems/flip-game-ii/description/

  • Solution:
class Solution(object):
def canWin(self, s):
"""
:type s: str
:rtype: bool
"""
def search(s):
if s not in mem:
mem[s] = any(not search(s[:i] + '--' + s[i+2:]) for i in range(len(s)) if s[i:i+2] == '++')
return mem[s]
mem = {}
return search(s)
Game theory: Solutions for coins in a line
2017-09-07

> Solutions for tree coins in a line problem

This is a post for game theory problems. All solutions are written in Python.

I didn’t have to put a lot of details here. Comment below if you have any issue.

Keep in mind: the current state is generated by its sub states (further states).

> Coins in a line I

  • Problem: http://www.lintcode.com/en/problem/coins-in-a-line/

    This problem start taking coins from the right side.

  • Solution:

    1. DP
    class Solution:
    """
    @param n: an integer
    @return: a boolean which equals to True if the first player will win
    """
    def firstWillWin(self, n):
    dp = [False] * (n+1)

    for i in range(1, n+1):
    if not (dp[i-1] and dp[i-2]):
    dp[i] = True
    return dp[n]
A complete solution for TinyURL (Leetcode System Design)
2017-07-13

Note: The solution is translated from the Segmentfault post over here. Thanks for liuqi627.

> Question Description

Over here

> S: Scenario

Long URL to short URL and reversed.

> N: Need (Assume the system is not massive if you are not sure)

> QPS (queries per second)

  • Daily User: 100M
  • Daily usage per person: (Write) long2short 0.1, (Read) short2long 1
  • Daily request: Write 10M, Read 100M
  • QPS: Since a day is 86400s approximately 100K.
Databases: you do not know
2017-07-05

> Implicit and Explicit join p169

> Explicit Join

SELECT CourseName, TeacherName
From Courses INNER JOIN TEACHERS
ON Courses.TeacherID = Teachers.TeacherID

> Implicit Join

SELECT CourseName, TeacherName
FROM Courses, Teachers
WHERE Courses.TeacherID = Teachers.TeacherID
Java: you do not know Ⅱ
2017-06-05

> Treemap, HashMap, LinkedHashMap

Q: Explain the differences between TreeMap, HashMap, and LinkedHashMap. Provide an example of when each one would be best.

A: The most important distinction between these classes is the time guarantees and the ordering of the keys.

  • HashMap offers O(1) lookup and insertion. If you iterate through the keys, though, the ordering of the keys is essentially arbitrary. It is implemented by an array of linked lists.
  • TreeMap offers P(logN) lookup and insertion. Keys are ordered, so if you need to iterate through the keys in sorted order, you can. This means that keys must implement the Comparable interface. TreeMap is implemented by a Red-Black Tree.
  • LinkedHashMap offers O(1) lookup and insertion. Keys are ordered by their insertion order. It is implemented by doubly-linked buckets.
Java: you do not know I
2017-05-29

Some basic knowledge of Java in the book[1]. Well, I pick the title “you don’t know”. Precisely, it’s something I don’t know while you may already knew years ago. But it just sounds so stupid to named after “Java: I don’t know”…

Your interviewer may be equally—or more—impressed if you can derive the answer than if you automatically knew it.

> Overriding

public double computeArea(Circle c) {...}
public double computeArea(Square s) {...}

Overriding, however, occurs when a method shares the same name and function signature as another method in its super class.