Eclipse: remove Java comments








  • remove all /** ... ... */ comments:


    Regular Expression: /\*(?s:(?!\*/).)*\*/
  • remove all /* ... ... */ comments:


    Regular Expression: /\*\*(?s:(?!\*/).)*\*/

see also




Python: read and write binary files









def copy(if_path, of_path):
with open(if_path, 'rb') as in_file, open(of_path, 'wb') as out_file:
while True:
chunk = in_file.read(1024)
if chunk:
out_file.write(chunk)
out_file.flush()
else:
break



Python: mutable byte array as buffer








bytearray function can be used to make a mutable byte array as buffer:

import struct
buffer = bytearray(8)
buffer[0]=1
buffer[1]=1
struct.pack_into('>ih', buffer, 2, 100, 200)
# to convert the array to str
print(bytes(buffer))

see also




python: join lists









list1 = ['a', 'b']
list2 = ['c', 'd']

list3 = list1 + list2



Python: encode integers to byte string









import struct
def int_to_bytes(value, size, big_endian=False):
bs = []
for i in range(size):
offset = i * 8
b = chr((value & (0xff << offset)) >> offset)
if big_endian:
bs.insert(0, b)
else:
bs.append(b)
return b''.join(bs)

def int32_to_bytes(value, big_endian=False):
return int_to_bytes(value, 4, big_endian)

def int64_to_bytes(value, big_endian=False):
return int_to_bytes(value, 8, big_endian)

if __name__ == '__main__':
# the two commands below do the same
print(repr(int64_to_bytes(65536, big_endian=True)))
print(repr(struct.pack('>Q', 65536)))

see also




python: print a string as hex bytes










':'.join(x.encode('hex') for x in 'Hello World!')



Executes in python CLI:

>>> ':'.join(x.encode('hex') for x in 'Hello World!')
'48:65:6c:6c:6f:20:57:6f:72:6c:64:21'



join binary strings in Python











b''.join(['abc', '\x01\x02\x03', 'efg'])




Execute it in python cli:

>>> b''.join(['abc', '\x01\x02\x03', 'efg'])
'abc\x01\x02\x03efg'



Python: get the length of a utf-8 encoded string









len(s.encode('utf-8'))



北美票房上亿的经典电影排名(截止2009年)[奥斯卡获奖影片]








年份片名北美票房(亿美元)点评
2008《黑暗骑士》5.33奥斯卡最佳男配角最佳影响效果
2008《WALL-E》2.24奥斯卡最佳动画长片
2007《料理鼠王》2.06奥斯卡最佳动画长片
2006《快乐大脚》1.98奥斯卡最佳动画长片
2004《超人总动员》2.61奥斯卡最佳动画长片
2003《指环王3》 3.77奥斯卡11项大奖包括最佳影片、剧本、导演
2003《海底总动员》3.40奥斯卡最佳动画长片
2002《指环王前两部曲》6.55奥斯卡6项大奖
200i《怪物史莱克》 2.68奥斯卡最佳动画长片
2001《美丽心灵》 1.71奥斯卡最佳影片导演剧本
2000《角斗士)》1.88奥斯卡最佳影片导演剧本影帝
1997《泰坦尼克号》6.01奥斯卡11项大奖包括最佳影片、剧本、导演
1997《尽善尽美》1.48奥斯卡影帝影后
1994《阿甘正传》3.30奥斯卡8项大奖包括最佳影片、影帝、导演、剧本



北美票房上亿的经典电影排名(截止2009年)[魔幻片]








年份片名北美票房(亿美元)
2009《哈利波特导混血王子》2.90
2008《暮光之城》1.91
2008《纳尼亚传奇2》1.42
2007《加勒比海盗3》3.09
2007《哈利波特-凤凰社》2.92
2007《斯巴达三百勇士》2.11
2006《加勒比海盗2》4.23
2006《博物馆奇妙夜》2.51
2005《内尼亚传奇》2.92
2005《哈利波特-火焰杯》2.90
2004《哈利波特-司兹卡班的囚徒》2.50
2004《北极特块车》1.63
2004《范海辛》1.20
2004《雷蒙斯尼奇的不幸历险》1.19
2003《指环王3》3.77
2003《加勒上七海盗》3.05
2002《指环王2》3.42
2002《哈利波特导密室》2.62
2001《哈利波特导魔法石》3.18
2001《指环王》3.15
2001《木乃俘归来》2.02
1999《木乃俘》1.55
1995《逃出魔幻纪》1.00



北美票房上亿的经典电影排名(截止2009年)[喜剧片]








年份片名北美票房(亿美元)点评
2009《宿醉》2.62票房神话人看了就服了
2009《下段结婚》1.49 
2009《百货战警》1.41难得的温馨
2008《功夫熊猫》2.15 
2008《马达加斯加2》1.80 
2008《特务行不行》1.35 
2007《怪物史莱克3》3.23 
2007《艾尔文与拢栗鼠》2.17 
2007《辛普森一家》1.83 
2007《一夜肚大》1.49 
2007《尖峰时刻3》 1.40 
2006《波拉特》1.29 
2006《博物馆奇妙夜》2.51 
2006《冰河世纪2》1.95 
2006《决乐大脚》1.98 
2005《婚礼傲客》2.09 
2005《神勇奶爸》1.13 
2005《新抢钱夫妻》1.10 
2005《四十岁老处男》1.09 
2005《马达加斯加》1.94 
2004《怪物史莱克2》4.41 
2004《登鱼黑帮》1.61恶搞黑帮电影
2004《初恋五+次》1.21 
2004《拜见岳父2》2.79 
2003《冒牌夭神》2.43某些经典笑段笑到我生活不能自理
2003《儿女一箩筐》1.39 
2003《气味相投》1.36 
2003《爱到屋倒房塌》1.33 
2003《非常小特务3》1.12 
2002《我的希腊婚礼》2.41 
2002《逍遥法外》1.65 
2002《圣诞决乐再疯狂》1.39 
2002《王牌大贱谍3》2.13 
2001《怪物史莱克》2.68 
2001《美国派2》1.45 
2001《怪医社德利2》1.13 
2001《公主日记》1.08 
2000《圣诞怪杰》2.60 
2000《男人百分百》1.83 
2000《拜见岳父》1.66 
2000《惊神尖笑》1.57无敌的恶搞作品
2000《肥佬教授2》1.23 
2000《卧底肥妈》1.18 
1999《王牌大贱谍2》2.06 
1999《冒牌老爸》1.63 
1999《落跑新娘》1.52 
1999《精灵鼠小弟》1.4史上第一部真人结合动画?
1999《新娘百分百》1.16 
1999《老大靠边闪》1.07 
1999《美国派》1.03 
1998《我为玛丽狂》1.76 
1998《呆呆向前冲》1.61 
1998《怪医社德利》1.44 
1998《轰天炮4》1.30难得的喜剧系列部部叫座
1998《尖峰a寸刻》1.41 
1998《淘气小兵兵》1.00 
1997《大话王》1.81 
1997《真的想嫉你》1.27 
1996《肥佬教;受》1.29 
1996《大婆俱乐部》1.05小孩很可爱哈
1995《逃出魔幻纪》1.00 
1995《鬼马小精灵》1.00 
1994《今年圣诞大事件》1.45 
1994《阿呆与阿瓜》 1.27 
1994《变相怪杰》1.19 
1993《肥妈先生》2.19 
1992《小鬼当家2》1.74 
1992《轰天炮3》1.45 
1992《修女也疯狂》1.40 
1992《护花倾情》1.22 
1992《粉红联盟》1.08 
1990《小鬼当家》2.86 
1990《至尊神探》1.04 
1989《轰天炮2》1.47 
1989《豆T小精灵》1.31 
1989《回到未来2》1.18 
1989《捉鬼蠢交死)2》1.12 
1989《小美人鱼》1.12 
1984《妙探出更》2.35 
1984《捉鬼敢死队》2.29鬼鬼都走可爱路线~异形女王主演哦



HTML5/Javascript to access local files system?








Short answer is: No. In April 2014, it was announced on public-webapps that the Filesystem API spec should be considered dead. Other browsers have showed little interest in implementing it.


Java: save a BufferedImage to PNG or JPG using Image IO








public static void saveAsPNG(BufferedImage img, File f) {

    ImageIO.write(img, "PNG", f);

}

public static void saveAsJPG(BufferedImage img, File f) {

    ImageIO.write(img, "JPG", f);

}



Upgrade existing Eclipse standard/classic to J2EE








go to the Help menu, choose Install New Software, and while Working With All Available Sites, choose the features you want from the Web, XML, Java EE and OSGi Enterprise Development category. If unsure, pick both the Eclipse Java EE Developer Tools and JST Server Adapters Extensions and proceed, allowing it to select dependencies for you.

For those certain that they only want to install selected parts of WTP, the Eclipse XML Editors and Tools selection is exactly as named while the Eclipse Web Developer Tools builds on that with HTML, CSS, and JavaScript tools, and supports deployable "static" web projects. The Eclipse Java Web Developer Tools adds support for JSP files (but not Java Servlets), and complete support for "dynamic" web projects requires the full Eclipse Java EE Developer Tools Feature.

See also




Ubuntu: Some index files failed to download








Symptom:
When running sudo apt-get update got the following error:
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/precise-backports/universe/i18n/Index  No Hash entry in Release file /var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise-backports_universe_i18n_Index

E: Some index files failed to download. They have been ignored, or old ones used instead.

Solution:
sudo rm -rf /var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise-backports_universe_i18n_Index
sudo apt-get update



Java: tuples (pairs, triplets)








public class Pair<X, Y> { 
  public final X x; 
  public final Y y; 
  public Pair(X x, Y y) { 
    this.x = x; 
    this.y = y; 
  } 
}

//    Unit<A> 
//    Pair<A,B> 
//    Triplet<A,B,C> 
//    Quartet<A,B,C,D> 
//    Quintet<A,B,C,D,E> 
//    Sextet<A,B,C,D,E,F> 
//    Septet<A,B,C,D,E,F,G> 
//    Octet<A,B,C,D,E,F,G,H> 
//    Ennead<A,B,C,D,E,F,G,H,I> 
//    Decade<A,B,C,D,E,F,G,H,I,J>  

see also




Java: create a new file also its parent directories as required








File file = new File("/tmp/a/b/c/1.txt");
file.getParentFile().mkdirs();
file.createNewFile();



Show apt-get (dpkg) history








/var/log/apt/history.log is the log file for apt-get install/remove: for example I want to find the command that I installed okular package:
cat /var/log/apt/history.log | grep Install | grep okular
This is useful if you want to find all the packages that were included automatically when you install a particular package. So that you can remove them all.

If the package was installed using dpkg command, you can find the log in /var/log/dpkg.log
cat /var/log/dpkg.log | grep adobereader