Goofy's Blog

Focus on Web Technology

Debug With Jekyll(rubygem)

折腾octopress的时候,遇到很多generate出错的情况,而提供的出错信息很难看出问题在哪,一般只能看到某个rb文件某行出了什么错,这个时候ruby的调试工具debugger就可以派上用场了。

1. 首先安装debugger gem

1
2
3
4
$ gem install debugger

# If install fails, try passing headers path
$ gem install debugger -- --with-ruby-include=PATH_TO_HEADERS

2. 如果使用bundler,把gem添加到Gemfile

1
gem 'debugger'

3. 在执行出错的rb文件中添加断点

xxx.rb
1
2
#在出错的语句前添加
require 'debugger'; debugger

然后重新执行出错的rake task, 程序会停在断点处,直接输入变量名来查看变量,输入help查看命令列表。debugger用法详见debugger tutorial

Volatile in Java

VIA: http://ifeve.com/jmm-faq-volatile/


原文:http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#volatile

译者:Alex

Volitile字段是用于线程间通讯的特殊字段。每次读volitile字段都会看到其它线程写入该字段的最新值;实际上,程序员之所以要定义volitile字段是因为在某些情况下由于缓存和重排序所看到的陈旧的变量值是不可接受的。编译器和运行时禁止在寄存器里面分配它们。它们还必须保证,在它们写好之后,它们被从缓冲区刷新到主存中,因此,它们立即能够对其他线程可见。相同地,在读取一个volatile字段之前,缓冲区必须失效,因为值是存在于主存中而不是本地处理器缓冲区。在重排序访问volatile变量的时候还有其他的限制。

How to Enter Special Characters in Ubuntu(Linux)

To enter a character by its code point, hold down Ctrl and Shift, type u followed by the four-character code point, then release Ctrl and Shift. If you often use characters that you can’t easily access with other methods, you might find it useful to memorize the code point for those characters so you can enter them quickly.

Ref: Ubuntu Documentation

How to Recover Files Deleted by Mistake in Git

  1. 找到commit记录如:f5810e08df0cb7cf82608d65cdb709cb430df2ea
  2. 执行以下命令即可恢复删除的文件
    1
    
    git checkout f5810e08df0cb7cf82608d65cdb709cb430df2ea path/to/file
    
  3. 重新commit push

Goodbye Microsoft, Hello Facebook!

VIA: 36kr.com

编者注:Philip Su在1998年加入微软,开始时是一位软件工程师。12年后,Philip Su从微软辞职,当时是微软的主群经理(Principal Group Manager),又一次以一位普通软件工程师的身份加入Facebook。Philip Su现任Facebook 伦敦办公室的主管。Philip Su在当时的离职信中写了他在微软工作12年比较独到的一些体会,希望对在职场的读者们有一些启发。这封离职信写于2010年9月3日。

开发中心资源管理技术方案

需求背景

一些公用的脚本,不方便互相引用,浪费人力。考虑把开发中心的文档作为资源,用于文档间互相引用,或者被任务引用

A Trap When Iterate on HashMap.entrySet()

If the map is modified while an iteration over the set is in progress (except through the iterator’s own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined.

Wrong code:

1
2
3
4
5
for (Entry<String, Long> entry : sizeMap.entrySet()) {
  if (xxx=xxx) {
      sizeMap.remove(entry.getKey());//这里删除会造成下载迭代时抛出java.util.ConcurrentModificationException异常
  }
}

Right code:

1
2
3
4
5
6
for (Iterator<Entry<String, Long>> itr = sizeMap.entrySet().iterator();itr.hasNext();) {
  Entry<String, Long> entry = itr.next();
  if(xxx=xxx) {
      itr.remove();
  }
}

Hello Blog on Github

Hello World!

Nihao!

Come on!

package com.github.abop

public class MyClass{
    public int main(){
        return null;
    }
}

Basic Linux Shell Commond (Include Vim)

linux

  • 执行命令后面加 & , 可以让任务后台运行
  • jobs查看当前任务
  • fg jobnumber切换某任务到前台
  • 普通任务执行时ctrl+z挂起到后台,但任务会暂停
  • bg jobnumber让挂起任务运行
  • fg 切换到前台

====

vim

  • ctrl+L refresh screen buffer
  • :split 分栏
  • ctrl+ 方向键 切换分栏
  • :e 打开文件
  • :ls 查看当前打开的buffer(文件)
  • :b num 切换文件(其中num为buffer list中的编号)
  • :bn — next buffer in the buffer list
  • :bp — previous buffer in the buffer list
  • :b# — previous buffer you was in
  • gg=G格式化文件(”start=end”)