其实决定下笔很久了,只是久久没开始写,总觉得写下来,就会逐渐淡忘。
2017年的12月,我从Umich master 毕业了,毕业前兮,自己面了一些公司,总觉得能毕业后马上能找到工作,所以OPT 开的很早,然而事与愿违,我一毕业就搬去加州开始找工作了,找了整整3,4个月,才终于找到一家公司,但只是个实习工作,现在回想起来,真的不知道自己是怎么在那几个月活下来的,就记得家旁边的一家中国人开的日料店的鸡排拉面很好吃,每次去我都点那个,去多了,老板娘常常跑来跟我聊天。每一个刚入职场的大学生的第一份工作都很难找,尤其加上我当时只有在实验室的的工作经验,更是雪上加霜,中小公司简历基本都是石沉大海,好不容易能面一些大公司,自己当时的刷题水平也不太够,也没有把握住机会。那段时间真的很少参加活动,整天窝在房间里刷题看书。很庆幸自己能坚持下来,其实当时最煎熬的是每周跟家长聊天,爸妈总会跟你说回来吧,回来找工作,但我自己并不想就这样放弃,灰溜溜的回国。那段时间的记忆已经模糊不清了,可能也没什么好回忆的,因为真的是太单调了。
5月,我开始在Cepheid 实习,做的的Angular, 和 Electron, 写一个前端的app, 后端的API 基本都是写好的。由于是毕业后的第一份工作,自己也是非常卖力,说实话,我的 performance 是相当好的,老板们对我也很满意,但是很不幸的是,当我实习快结束的时候收到消息,说公司没有full time 的职位了,没有办法hire 我。我很无奈,但是无能为力。后面我找到工作后,他们又联系我,有head count 了,要不要回去,不过这是后话了。
8月之后我又开始了“紧张又刺激的”找工作活动,这次真的是被逼上了绝路。
这期间有一个,是吴恩达的公司,deep leaning AI, 当时我并不太了解吴恩达,只知道他是AI 界的,但没想到这么大牛。去他家面试的过程也是一波三折,那天面完3轮 onsite, HR 突然跟我说要加面一轮,跟吴恩达,我没多想就说好的。当时我确实那天面试面的都挺好的,最后一轮其实就是跟吴恩达聊聊天,但是我是完全没准备过 behavior 的,没想到踩了坑。他问我为什么毕业这么久了还是没找到工作,我就跟他说,我面了一些大公司,但可能 LeetCode 的水平还不够。我自己也确实表现的太不自信了,但吴恩达连 LeetCode 都没听过,于是我给他打开了 LeetCode 的网站,并告诉他这是个刷 coding 题的网站。结果就是在 Hire debrief meeting 上,吴恩达给了我 no, 其他人都觉得我蛮好的。这个是 HR 小姐姐跟我说的,她说别跟面试官说什么 LeetCode 什么的,吴恩达好像是因为这个给我 no 的。可能是他觉得现在的 no grad 都只会刷题,并不会真正的 coding 吧,也可能我其他的 behavior questions 回答的也不是太好。但他们没有直接把我拒了,HR 安排了我下周周一再来跟他们的一个 manager 再面一轮,从这儿也能看出来他们是有想 hire 我的。结果面完过了两天把我还是给拒了。
一晃到了10月份,这是我来加州的第10个月了,还没找到一份正式的工作。当时面了FB, 然而我也没能把握住机会。这时的我陷入了对自己深深的怀疑,也开始对刷题进大厂的机制感到深深的厌恶。
幸运的是,跟自己关系很好的一个学长能帮我refer 华为了,于是简单的面了一下,通过了。其实我的方向跟他们做的CV 方向差的很多,之前在实验室做的也只是数据处理方面的东西,并不会机器学习,但多亏了那个学长话语权比较大,说服了 manager 。这算是一个契机也是一个转折点吧。之后的几个月,我开启了简单平凡的社畜生活,虽然跟我当时想做 Full stack 的意愿相背了,但是工作本身还是很有意思,有很多挑战的。
只是,没想到这样简单的生活,也被国际局势给打破了。2018 年6月,处于中美贸易战的影响下的华为,不得不作出裁员所有美国branch 的engineer team 。其实早在3月份,manager Lei 就跟我们说,公司有可能不行了,我作为manager 会做尽可能的力,但是你们也要自保。意思就是跟我们说让我们开始找工作了。在那样的大趋势下,我能感受到招聘市场的血腥味,一个虎落平山的巨头,几乎所有公司的HR 都闻道了 fresh meat 的味道,一段时间内,的确是有很多的HR 联系我,但由于我在公司也没有几个月的经历,真正能拿到面试的也屈指可数。
那几个月,公司的同事们都被裁员的阴影给笼罩着。不过可能是因为有跟自己同病相怜的小伙伴,这次刷题并没有那么孤单无助。我们几乎每天下班都在刷题,吃完饭就去图书馆或者奶茶店开始刷题。上班也会摸摸鱼,刷刷题,周末基本就是泡在图书馆。令我印象最深的是,当时大家都知道自己要被裁员了,我的老板突然找到我说,能不能教他刷题,我真的一脸懵逼。
当时面了一些公司,真正能走到最后的只有Google 和 Argo AI, 当时Google 是过了Hiring Committee , 在team match 阶段,但由于那两轮ML 面试面的不太好,他们把我放到了 general SDE 的 pool 里,而且是SDE1 (狗家的3), 我也是非常不爽,因为面我这两轮的的两个中国人,一个是做搜索的,一个是做Google travel 美食页面推荐算法的,我是做CV 的,大家确实都是做ML, 但是domain 差的真的太多了,他们能面我的也只是最最基础的一些ML 的东西,我相信很多从Deep learning 开始学起的同学都会感同身受,因为自己已经不处于那个时代了,所以像 SVM, Decision tree 之类的算法,只是学过,并没有实际上用过,对这些基础算法的理解也是浅尝辄止。所以自然的这两轮面的不太行,但我想Google 这么大,就找不出两个做 CV 的来面我吗? 真的是很无奈。
面Argo AI 的时候,那个算是我最后一个Onsite Interview 了,因为不行就去 Google , Google 最后没 match 上的话,那就滚回国了。可能当时面试的心态比较放松了,也可能是因为之前确实面过很多公司了,综合实力上那个是我当时的巅峰状态了,面下来的结果非常好。超乎我的意料之外,我也是第一次别人跟我说 manager 给了我strong hire 。我内心真的特别感动,想到自己来湾区的这一年半,为了找工作面试付出的种种种种,各种思绪涌上心头,哇的一下就哭了出来。后面老板和组员还给发了 offer 的人发邮件,表示对自己的重视和欢迎,当然他家的包也确实挺高的,所以我也没有多想,周五发的offer ,周一跟HR 周旋了下,就sign 了。当时那么果断的签了公司,其实也表现出自己的稚嫩,每个offer 都由上升的空间,我只给自己的offer sign on多加了一万,但我感觉因为我面的特别好,至少可以多个3万。
在 Argo 的日子过得很开心,组里的tech lead Richard 是我的mentor ,我们一起做Traffic light classifer, 模型很unique, 在任何public 的paper 应该都看不到这样的模型,工作内容很有挑战性,我也能感受到自己成长的非常快。组里的几个tech lead都是偏技术宅型的,基本我每次码代码码累了,抬头看他们,他们都在盯着屏幕,一天也很少有瞎转悠或者划水,在他们的影响下,我自己也养成了这种专注的习惯,所以在组内我的performance一直都还不错。
但是悲剧又一次发生在我身上了,毫无征兆的,20年8月初的一天,我突然发现我的电脑完全没法使用了,公司的security组的人给我发了一封邮件,我的同事发微信跟我说,老板宣布了我已经不在这个组了,我一脸懵逼,然后下午我就参加了他们发的meeting邀请,是关于我的一个hash key,我上传到了我自己github 的dotfiles里。有自己github dotfiles仓库的人都知道,这个仓库就是同步各个电脑上配置用的,他们说我19年刚入职的时候,把一个artifactory key,上传到了自己的github上了,我隐约记得有这个事情,而且当时是Github给我发邮件提醒了。但是我当时是忘记ignore那个有这个key的文件了,所以我git ignore了以后再force push了。结果好像是因为即使你force push了,这个commit并不会消失,所以这个key一直被暴露在public下。19年到现在,这个key也被regenerate了几次,我不确定因为这个事情,到底有没有hacker获取到了公司的数据,给公司造成了损失,但是他们在我入职第11月的时候跟我说我入职第一第二个月的一个错误,要知道,第12个月就可以拿到第一年的股票了。而且Github在19年给我发了邮件的,我不相信公司当时没有收到类似的邮件,但他们选择在这个时候提出来,我不得不怀疑是有意而为之的。
这件事有个后续,就是过了大概4个月,我们组里的另一个中国人,因为跟我一模一样的事情,也被lay off了。这里澄清一下,因为这些事情很明显都是无意为之,没有人蠢到偷公司东西会把key上传到public的github repo的,所以我们也没有任何刑事和法律责任。但是这件事给我提了个醒,就是在公司,不犯错,比自己绩效有多好多好要重要的多。
因为这件事,我很受打击,但是并没有时间给我消沉,我失落了一天,第二天就调整好状态开始找朋友refer了,开始找工作了。幸运的是,没过多久我我就拿到了黑芝麻的offer, 紧接着亚麻也给我offer了。于是我开始边在黑芝麻工作,边等亚麻这边处理我的offer。
终于在21年1月底,我回国了,在国内亚麻入职的,但是是给温哥华的组干活。后续在亚麻遇到的点点滴滴也足够我再吐槽吐槽了,不过这是后话了。留到下次吧。
2021/12/04Ting Zhou
]]>Fortunately, I realized there is a built-in feature call GPG forwarding that allows you to authorizethe server side request in the client side.
The idea is to forward your client sidse GPG socket to your server side, so that every time youtrigger a GPG authentication in server side, it can pop the GPG authentication GUI (pinentryprogram) in your local machine.
Generate ssh config with gpg forwarding enabled using the following command. This will append aconfig to your ~/.ssh/config
.
generate-ssh-gpg-config kuro 10.0.0.3 ztlevi |
You can either add StreamLocalBindUnlink yes
to your /etc/ssh/sshd_config
and restart yoursshd service. Or use ssh-with-gpg-socket-deleted kuro 10.0.0.3 ztlevi
to kill remote gpg-agentand then create a ssh session with local gpg forwarded.
Copy the puclic key to the remote machine
scp $HOME/.gnupg/pubring.kbx kuro:/home/ztlevi/.gnupg |
If you already exported it, you can do
gpg --import mypublickey.pub |
Encrypt to a file and then decrypt. You can try both on client and server side.
echo "test" | gpg --encrypt -r <your-gpg-email> |
alias gpg-restart="gpgconf --kill gpg-agent" |
I have to say BSPWM is not that friendly for the first-time user. It comes with a blank screenwithout anything. While you could something there by forking something’s setup. But it might notworking for you cuz it’s really easy to break some dependencies on your system.
I would recommend you to start with something like Awesome tiling window manager. It comes with morebuilt-in features. But I think overall BSPWM is a good fit for me. Polybar is supported in BSPWM andthe keybinding system is clean.
I forked Henrik Lissner’s dotfiles setup last year. So thanks for theamazing scripts that manage all the binaries and dependencies across multiple OS.
There are scripts enabled multi-monitors support.
These scripts basically check if there is any window in the current monitor is on the direction ofthe current window. If not, then it will check the next monitor.
There are many things needs customization to support 4K monitors.
I’m putting a lot of effort to make HDPI support comes out of box. Basically, I’m using xrandr
tofigure out the connected monitor resolution. Then calculate a SCALE
factor based on theresolution. Passing that across multiple applications to make HDPI like a built-in feature.
In .xprofile
.
RESOLUTION=$(xrandr -q | grep primary | grep ' connected' | cut -d' ' -f4 | cut -d 'x' -f1) |
Some apps can use system variables in their configuration. For example, polybar
.
In run-polybar.sh
:
MONITOR=$(xrandr -q | grep primary | grep ' connected' | cut -d' ' -f1) |
In polybar config:
[bar/side] |
There are apps cannot use system environment variables. So I pass different configs.
if [ "$GDK_SCALE" -eq 2 ]; then |
This is a light weight and fully customizable status bar. You could put almost everything there.
I have a clickable WIFI, sound, and icon workspaces module.
While there are tons of themes on the web. Take a look athere.
I don’t know what other people typically do to modify settings in tiling window mangers. Becausethey usually don’t ship with setting applications.
So I would also install Gnome and it’s applications just so I can modify the settings like Bluetoothor WIFI.
The reason most people choose tiling window manager is because it’s productive and cool. Talkingabout productivity, there won’t be a huge difference between tiling window manager and normal onesif you just use one or two monitors. It will be faster because you don’t need to move your hands tothe mouse and then move back. Everything is under keyboard.
But the productivities will scale up when u have 4 or more monitors. In this case, a multi-monitorsolution will be a life saver.
And finally, it’s cooooooool!
If you’re instead in tiling window manager. You’re welcome to fork my setup .
]]>cd
? ranger
? nnn
? t a Well, these are not desinged for navigatingprojects and they really do their jobs but not so efficient.Let me introduce the fzf_projects
.
First, you need to install fzf. Simply go through the tutorial here.
Second, put the following code in your shell configuration file.
Note:
project_roots
is a list of directories that projects inside within depth 1 will be added as projectscandidates.developer_root
is a directory that project inside within depth 2 will be added.
# Switch projects |
Third, source your shell configuration again or open a new terminal window. Trigger fzf_projects
by input pp
.
projectile
is amazing. It helps people to quickly switch between projects. Unfortunatelly, it cannot automaticallyscan the projects on your machine and load them when you first time fire projectile.Also, it doesn’t really remove those invalid project entires for me. For example, there is a git projcet under~/Developer/dummy-git
and I move this projcet to ~/Developer/new-git
. Both entires will exists every time I triggerM-x counsel-projectile-switch-project
(or helm-projectile). It makes me confused sometimes.
Here is the solution. For me, basically I every project I created is by git. So I utilzed the magit-list-repos-1
funcin magit
. For those of you use other source control tool or .projectile
in your project, you might need to find thecorresponding func or write your own.
(defun append-to-list (list-var elements) |
Since loading magit
takes me roughly 1.5 seconds on my machine and I don’t really need to update projectile repos onbooting Emacs, I hook the update func after magit
. And I bind a key for update-projectile-known-projects
to manuallytrigger it if needed.
Thats all for this post. I hope you enjoy it.
]]>It’s basicly just hacking your IP kernel, adding rules for your intranet. Now let’s get started.
Your probably need to install the net-tools
before getting started. In ubuntu, you can usesudo apt install net-tools
.
First, keep in mind, you will only need to have a default IP rule. Check your IP routes by ip route list
, orroute -n
.
Here is mine when I both connect to ethernet and wifi.
default via 10.193.35.1 dev enp6s0 proto static metric 20100 |
You can tell from above there are two default rule in my IP kernel. In this case, our goal is to delete the ethernetdefault and add some specific rules to route intranet IP.
Note: enp6s0 is my ethernet device name, and wlp5s0 is my wifi device name.
Second, we can remove the default ethernet rule with:
sudo route del default gw 0.0.0.0 enp6s0 |
Then, we add the network segment 10.213.37.0/24
rule, routing it via the intranet gateway, in my case, it’s theintranet router’s IP address 10.193.35.1
.
sudo ip route add 10.213.37.0/24 via 10.193.35.1 dev enp6s0 |
Note:
/24
is the subnet mask = 255.255.255.0
Finally, if you use a domain rather than ip as default, you need to add the entry to /etc/hosts
to help the PC resolvethe IP when it cannot reach the proper DNS server.
For example:
172.217.195.106 www.google.com |
That’s all for the tutorial. You might need to adapt this tutorial in your own scenario. But all the tools are on thetable, feel free to hack it by yourself.
]]>cspell
is a command line tool and librray for spell checking code. It supports camel case checking and is reallypopular in VSCode, roughly 1,350,000 downloads so far.As for Emacs, there are many options there but none of them seems working perfectly for me. But I have to say they arepowerful tools.Besides wucuo is kind of cool tool as well because it supports camel case as well.
I found this cspell
and it works great in VSCode and I decide to move this to Emacs. A tricky thing is it a plainchecker and doesn’t help to provide correction candidates for you, but flyspell does. So it better just add aflycheck-checker
rather hack on Flyspell
.
Here is the code:
(with-eval-after-load 'flycheck |
Note: If you feel lagging, you can set
flycheck-idle-change-delay
to 3s or removeidle-change
fromflycheck-check-syntax-automatically
.
Furthurmore, you can customize it with cspell.json
]]>So here is a simple trick, I just check the first 30 line of the opened file. If first line is over 1000 in width, thenit just enable fundamental-mode
which works perfectly for these files.
;; if the first line is too long, enable fundamental by default |
This piece of code is from spacemacs, we have to set a couple variables. But you could have your own version.
(setq spacemacs-large-file-modes-list '(archive-mode tar-mode jka-compr git-commit-mode image-mode |
Recently, I’m working on a React Native project. I have tried using Emacs to do the coding, but Icannot really pick up the whole new stuff without a fancy auto-completion or finding definitionssince the syntax of React is so different and special. That’s why I pick up Webstorm as aworkaround. And there, I find a way to build my Jetbrain IDEs just like Spacemacs.
Like I said in my previous post, space way is good for Vim users and only Vim can do this because ithas other modes other than just insert mode. In this case, key bindings will never be a problem. Weare using the sticky key sequences and prefix key for memorization.
Welcome to the heaven!!!
If you’re too lazy to read the whole stuff, grab my.ideavimrc on Github
Using space key as the leader is a very popular way of editing, navigation, andcommanding. There is never an easy way to get used to new shortcuts, but trust me, you woulddefinitely like it once you use it.
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 actuallypress these keys.
This looks so stupid when you compare it with just Space Space in Vim’s normal or visualmode. And by saying Space Space, it’s a sticky key binding which means you just typespace key twice in sequence. And you can just set your hands as the default typingposition shown in this picture.
Well, now you probably get the point of using space key. But there is more of it.
Since sticky keys are just key sequences, you can cluster a lot of similar commands to a prefix likespace f (file related commands). For example, space> f f go to the explorer,space> f s save file and space> f S save all. In this case, you won’t mess upwith these keys because they have the same prefix space> f.
For the normal and visual mode, They are pretty much the same. But they can do much more now inspace way.
The space w m and other window pop up combination is just beautiful.
The most used ones are in bold text.
Note: The leader key is space
Key | Description |
---|---|
C-i | Forward |
C-o | Go back |
g d | Go to declaration |
g h | Go to Documentation |
g r | Find Usages |
g s | Go to Symbol |
leader ' | Active terminal window |
leader R | reload ~/.ideavimrc |
leader a a | Select All |
leader a l | Prompt action list |
leader b b (<CR>) | Recent files (You can still use command+e or ctrl+e) |
leader b i | Active structure tool window |
leader b u | Reopen Closed Tab |
leader c c | Go to Class |
leader d D | Debug Class |
leader d d | Debug |
leader e e | show error description |
leader f T | Select current file in project view |
leader f b | Show Bookmarks |
leader f d | Smart search launcher (You have to install Dash or Zeal first) |
leader f f | Search Everywhere |
leader f s | save all files (I still use command+s or ctrl+s) |
leader f t | Active file tree window |
leader i m | Implement Methods |
leader g S/ | Active version control window |
leader g s | Vsc quick list pop up |
leader j i | Fire structure pop up (similar to structure tool) |
leader j j | Ace Action |
leader j l | Ace Line Action |
leader m = | beautify file |
leader r R | Run Class |
leader r p | Replace in project |
leader r r | Run |
leader s s | Stop |
leader s p | Search in project |
leader space | Go to Action |
leader t b | Toggle Bookmark |
leader t t | Toggle Line Breakpoint |
leader w [lhjk] | navigate window |
leader w c | close window |
leader w m | hide all windows except the editor tabs (You can invoke again to revert) |
leader w s | split window horizontally |
leader w v | split window vertically |
leader w z | Toggle Zen mode |
z C | collapse all region |
z O | expand all region |
z c | collapse region |
z o | expand region |
.ideavimrc
file in home directory, just like ~/.ideavimrc
.In case you want to sync your settings across multiple machines, you should checkout the SettingRepository >here.
~/.ideavimrc
." ============================================================================ |
Note: You have to disable the C-a, C-e in Jetbrain IDE to have the visual modeworking correctly.
You can click the from here to find the action by key.
~/.ideavimrc
.The ugly <Backspace><Backspace><Backspace><Backspace><Backspace>
is because when we enter thecommand mode from visual mode, we have :'<,'>
. The extra chars need to be deleted before we invokethe actions.
let mapleader = " " |
" select occurrence, they do not work when editing |
set gdefault |
For the build, the liquid cooler cannot fit in the top of the case with this special motherboard. Iremove the front fan and put it at the top of the case. Then I install the liquid cooler up frontthe case.
I just follow the installation fromTonymacx86 High Sierra Installationand that’s works for me.
The SMBIOS setting I’m using is iMac 14,2. I was using iMac 18,3 before but once I switch to Vegagraphics card, it will cause black screen. So I suggest to stick with 14,2.
The only issue I have is the audio. I am not sure it’s the macOS version 10.13.4’s problem or Vegagraphics card’s. A quick fix is using USB to headphone jack converter. You can buy anyone fromAmazon.
In 90% cases, you can go ahead update your system without any problem. But be careful, and check outTonymacx86’s update posts. For example, youmight have to update your clover bootloader or replace your old apfs.efi to the new one.
]]>For those of you love simplicity and complexity that Chrome provides, and also running a Hackintoshwith Nvidia drivers, you might notice it’s super lagging when browsing or even just open yourChrome.
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 inGoogle Chrome. I feel like my Chrome has revived after all the suffer.
To disable hardware acceleration in Google Chrome, follow the steps below:
Recently, I found Hugo, which is another static site generator, comes with some usefulshortcodes 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 boringman am I.😂😂😂 So I just put other people’s nice one here as examples.
For youtube or other video resources, you can embed videos withhexo-tag-video. Thanks geekplux for this interesting plugin.
Very easy to install. Here is an example.
{% video <iframe width="560" height="315" src="https://www.youtube.com/embed/k5X2Hb3tc2s" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> %} |
For Instagram, hexo-tag-instagram is built bytea3. He built hexo-tag-twitter as well. Greatjob done, tea3!
{% instagram instgram-url %} |
{% twitter tweet-url %} |
These days, I was working on a React Native project. In the meanwhile, I found it’s kind of hard tocatch up the modern syntax of Javascript, so as for imenu (a built in project structure menu bar inEmacs).
Fortunately, there are so many people love Emacs and contribute to it. Thanks for Chen bin’s greatpost. I just put down moreimenu generic expressions for modern Javascript like React, Vue. This helps me navigate and gothrough projects.
A quick look a the result is here.
Note: To get functions like
componentDidMount
, and excludeif, for, while
, plain regexp inEmacs seems not working. At least I couldn’t find an easy solution like[^if|for|while]
. Butsinceimenu-generic-expression
takes functions as parameters, I created another function to wrapone generic expression. Finally it works but as you can see, it’s not beautiful.
(defun my-js2-mode-hook () |
Using space key as the leader is a very popular way of editing, navigation andcommanding. There is never an easy way to get used to new shortcuts, but trust me, you woulddefinitely like it once you use it.
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 actuallypress these keys.
This looks so stupid when you compare it with just Space Space in Vim’s normal or visualmode. And by saying Space Space, it’s a sticky key bindings which means you just typespace key twice in sequence. And you can just set your hands as the default typingposition shown in this picture.
Well, now you probably get the point of using space key. But there is more of it.
Since sticky keys are just key sequences, you can cluster a lot of similar commands to a prefix likespace f(file related commands). For example, space f f go to the explorer,space f ssave file and space f Ssave all. In this case, you won’t mess up withthese keys because they have the same prefix space f.
Spacemacs has a hybrid mode that takes the normal and visual modes’ key bindings from Vim whilestill using the general Emacs key bindings in insert mode. To be honest, it’s super smart way ofediting.
The Unix key bindings (C-a->home, C-e->end, C-b->back,C-f->forward, C-n->next line, C-p->last line) work in almost everyMac application. You probably never find out they work out of box in your Mac or Linux, but many ofyour guys don’t know about it.
So, why the hell people want to use Unix key bindings in their machines?
There are many reasons:
As for the normal and visual mode, They are pretty much the same. But they can do much more now inspace way.
Note: The leader key is space
Key | Description |
---|---|
leader space | show commands |
leader b b | quick open (see your opened files) |
leader f f | go the explorer |
leader f s | save file |
leader f S | save all |
leader = | beautify file |
leader w [lhjk] | navigate window |
leader w v | split vertically |
C-g (Optional) | ESC |
User Setting
(You can find out how to get tothe User Setting
over here).{ |
keybindings.json
.Note: You can find your keybindings.json here.
[ |
Again, I don’t have much time putting down a lot of details here…
https://leetcode.com/problems/flip-game-ii/description/
class Solution(object): |
https://www.hackerrank.com/challenges/a-chessboard-game-1/problem
n = int(input()) |
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).
Problem: http://www.lintcode.com/en/problem/coins-in-a-line/
This problem start taking coins from the right side.
Solution:
class Solution: |
dp[i]
represents if the current player can win when i~n coins have been selected.
For not (dp[i-1] and dp[i-2])
, dp[i]
is True
when and only when there is a False
in dp[i]
's sub statesdp[i-1]
and dp[i-2]
. Which means, there is a possible lose for his opponent. dp[i]
's sub states represent thecoins his opponent can gain. We want this value smaller so that we can gain more.
class Solution: |
Problem: http://www.lintcode.com/en/problem/coins-in-a-line-ii/
This problem starts taking coins from the left side.
Solution:
class Solution: |
dp[i]
means the max coins can gain from i to end
sum[i]
means the sum from i to end
dp[i] = max(values[i] + sum[i+1] - dp[i+1], values[i] + values[i+1] + sum[i+2] - dp[i+2])
=>dp[i] = sum[i] - min(dp[i+1], dp[i+2])
class Solution: |
Problem:
There are n coins in a line. Two players take turns to take a coin from one of the ends of the line until there are nomore coins left. The player with the larger amount of money wins.
Could you please decide the first player will win or lose?
Example
Given array A = [3,2,2], return true.
Given array A = [1,2,4], return true.
Given array A = [1,20,4], return false.
Solution:
class Solution: |
dp[i][j]=max(values[i]+sum[i+1][j]-dp[i+1][j], values[j]+sum[i][j-1]-dp[i][j-1])
values[i]+sum[i+1][j]
and values[j]+sum[i][j-1]
are equal to sum[i][j]
So dp[i][j]=sum[i][j]-min(dp[i+1][j],dp[i][j-1])
class Solution: |
Over here
Long URL to short URL and reversed.
Write 100, Read 1K
(Thousand level can be handled by a single SSD MySQL Machine)
Storage is not the problem for this kind of system. Service like Netflix may have storage issues.
Through SN analysis, we could have a big picture of the system. In general, this system is not hardand could be handled by a single SSD Machine.
Only one service: URLService
Request Body: {url=longUrl} e.g. {“longUrl”: “http://www.google.com/”} Return OK(200), short_url isincluded in the data
OK, let’s talk about the system algorithm. There are following solutions:
Hash function:
long_url -> md5/sha1
http://site.douban.com/chuan -> c93a360dc7f3eb093ab6e304db516653
http://site.douban.com/chuan -> dff85871a72c73c3eae09e39ffe97aea63047094
These two algorithms could make sure hash values are randomly distributed, but the conflicts areinevitable. Any hash algorithm could have inevitable conflicts.
Pros: Simple. We could take the first 6 chars of the converted string.
Cons: Conflicts.
Solutions: 1. use (long_url + timestamp) as the hash function key. 2. When conflicts, regeneratesthe hash value(it’s different because timestamp changes).
Overall, when urls are over 1 billion, there would be a lot of conflicts and the efficiency couldbe very low.
Each short_url represent a decimal digit. It could be the auto_increment_id in SQL database.
public class URLService { |
One table (id, long_url). id is the primary key, ordered by long_url
The basic system architecture:
Browser <-> Web <-> Core <-> DB
Use Memcached to improve response speed. When getting long_url, search in the cache first, thendatabase. We could put 90% read request on the cache.
Different locations use different web server and cache server. All the areas share a DB used tomatch the users to the closest web server (through DNS) when they have a miss on the cache.
Database Partitioning
The best way is horizontal sharding.
Currently table structure is (id, long_url). So, which column should be sharding key?
An easy way is id modulo sharding.
Here comes another question: How could multiple machines share a global auto_increment_id?
Two ways: 1. use one more machine to maintain the id. 2. use zookeeper. Both suck.
So, we do not use global auto_increment_id.
The pro way is put the sharding key as the first byte of the short_url.
Another way is to use consistent hashing to break the cycle into 62 pieces. It doesn’t matter howmany pieces because there probably would not be over 62 machines (it could be 360 or whatever). Eachmachine is responsible for the service in the part of the cycle.
write long_url -> hash(long_url)%62 -> put long_url to the specific machine according to hash value-> generate short_url on this machine -> return short_url
short_url request -> get the sharding key (first byte of the short_url) -> search in thecorresponding machine based on sharding key -> return long_url
Each time we add a new machine, put half of the range of the most used machine to the new machine.
Put Chinese DB in China, American DB in the United States. Use geographical information as thesharding key, e.g. 0 for Chinese websites, 1 for American websites.
]]>SELECT CourseName, TeacherName |
SELECT CourseName, TeacherName |
Normalized databases are designed to minimize redundancy, while denormalized databases are designed to optimized readtime.
In a traditional normalized database with data like Courses and Teachers, Courses might contain a column calledTeacherID, which i a foreign key to Teacher. One benefit of this is that information about the teacher (name, address,etc.) is only stored once in the database. The drawback is that many common queries will require expensive joins.
Instead, we can denormalize the database by storing redundant data. For example, if we knew that we would have to repeatthis query often, we might store the teacher’s name in the Courses table. Denormalization is commonly used to createhighly scalable systems.
Cons of Denormalization | Pros of Denormalization |
---|---|
Updates and inserts are more expensive. | Retrieving data is faster since we do fewer joins. |
Denormalization can make update and insert code harder to write. | Queries to retrieve can be simpler (and therefore less likely to have bugs), since we need to look at fewer tables. |
Data maybe inconsistent. Which is the “correct” value for a piece of data? | |
Data redundancy necessitates more storage. |
Database questions often have some ambiguity, intentionally or unintentionally. Before you proceed with your design, youmust understand exactly what you need to design.
Imagine you are asked to design a system to represent an apartment rental agency. You will need to know whether thisagency has multiple locations or just one. You should also discuss with your interviewer how general you should be. Forexample, it would be extremely rare for a person to rent two apartments in the same building. But does that mean youshouldn’t be able to handle that? Maybe, maybe not. Some very rare conditions might be best handled through a workaround (like duplicating the person’s contact information in the database).
Next, we should look at the core objects of our system. Each of these core objects typically translates into a table. Inthis case, our core objects might be Property, Building, Apartment, Tenant and Manager.
Outlining the core objects should give us a good sense of what the tables should be. How do these tables relate to eachother? Are they many-to-many? One-to-many?
Finally, we fill in the details. Walk through the common actions that will be taken and understand how to store andretrieve the relevant data. We’ll need to handle lease terms, moving out, rent payments, etc. Each of these actionsrequires new tables and columns.
]]>Q: Explain the differences between TreeMap, HashMap, and LinkedHashMap. Provide an example ofwhen each one would be best.
A: The most important distinction between these classes is the time guarantees and the ordering ofthe keys.
Q: What suppose to the key ordering with the input ordering {1, -1, 0}?
A: | HashMap | LinkedHashMap | TreeMap | |--------------|---------------|------------| | anyordering | {1, -1, 0} | {-1, 0, 1} |
Q: When might you need ordering in real life?
A:
Generally, unless there is a reason not to, you would use HashMap.
Q: Explain what object reflection is in Java and why it is useful?
A: Object Reflection is a feature in Java that provides a way to get reflective information aboutJava classes and objects, and perform operations such as:
Q: There is a class Country that has methods getContinent() and getPopulation(). Write afunction int getPopulation(List
A: This question really comes in two parts. First, We need to generate a list of the countries inNorth America. Then, we need to compute their total population.
Without lambda expression, this is fairly straightforward to do.
int getPopulation(List<Country> countries, String continent) { |
To implement this with lambda expression, let’s break this up into multiple parts.
int getPopulation(List<Country> countries, String continent) { |
Alternatively, the following code will disregard the countries no within continent according tothe sum.
int getPopulation(List<Country> countries, String continent) { |
Q: Using Lambda expressions, write a function List
A: To implement this approach using lambda expressions, we can do the following:
List<Integer> getRandomSubset(List<Integer> list) { |
Your interviewer may be equally—or more—impressed if you can derive the answer than if youautomatically knew it.
public double computeArea(Circle c) {...} |
Overriding, however, occurs when a method shares the same name and function signature as anothermethod in its super class.
Java’s collection framework is incredibly useful.
Q: In terms of inheritance, what is the effect of keeping a constructor private?
This has direct implications for inheritance, since a subclass class calls its parent’s constructor.Who, other than A, can access A’s private methods and constructor? A’s inner classes can. Thismeans, the class A can be inherited, but only by its own or its parent’s inner classes.
Q: In Java, does the finally block get executed if we insert a return statement inside the try blocko a try-catch-finally?
Yes, it will get executed. The finally block always executes when the try block exits. This ensuresthat the finally block is executed even if an unexpected exception occurs. But finally is useful formore than just exception handling — it allows the programmer to avoid having cleanup codeaccidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block isalways a good practice, even when no exceptions are anticipated.
Note: If the JVM exits while the try or catch code is being executed, then the finally block may notexecute. Likewise, if the thread executing the try or catch code is interrupted or killed, thefinally block may not execute even though the application as a whole continues.
Despite their similar sounding names, final, finally and finalize have very differentpurposes. To speak in very general terms:
The final statement has a different meaning depending on context.
There is an optional finally block after the try block or after the catch block. The finallyblock is often used to write the clean-up code. It will be executed after the try and catch blocks,but before control transfers back to its origin.
The automatic garbage collector calls the finalized() method just before actually destroying theobject. A class can therefore override the finalized() method from the Object class in order todefine custom behavior during garbage collection.
protected void finalize() throws Throwable { |
Q: Explain the difference between templates in C++ dand generics in Java.
Many programmers consider templates and generics to be essentially equivalent because both allow youto do something like List
The implementation of Java generics is rooted in an idea of “type erasure”. This techniqueeliminates the parameterized types then source code is translated to the Java Virtual Machine(JVM)byte code.
For example, suppose you have the Java code below:
Vector<String> vector = new Vector<String>(); |
During the compilation, this code is re-written into:
Vector vector = new Vector(); |
The use of Java generics didn’t really change much about our capabilities; it just made things a bitprettier. For this reason, Java generics are sometimes called “syntactic sugar”.
This is quite different from C++. In C++, templates are essentially a glorified macro set, with thecompiler creating a new copy of the template code for each type.
In Java, static variables are shared across instances of Class, regardless of the different typeparameters.
There are other differences between Java generics and C++ templates.
Cracking the Coding Interview, 6th Edition. ↩︎