Search This Blog

blogger: label search url

  • To search for the posts with label: "YourLabel":
        http://YourBlog.blogspot.com/search/label/YourLabel
    
  • For the labels contains blank space, e.g "Your Label", use %20 replace the space:
        http://YourBlog.blogspot.com/search/label/Your%20Label
    
  • To search for posts with multiple labels, e.g. Label1 and Label2:
        http://YourBlog.blogspot.com/search?q=label:Label1+label:Label2
    

Tips

  • You can use the label search urls as Top Tabs to categorize your posts.

Mac OS X Lion: Install alarm clock widget

Mac OS X: extract files from .pkg installer packages

  • To list the contents of the .pkg:
    gunzip  -c /path/to/XXX.pkg/Contents/Archive.pax.gz | pax
    
    For example:
    gunzip  -c /Volumes/iMac\ EFI\ Updater/iMacFirmwareUpdate.pkg/Contents/Archive.pax.gz | pax
    
  • To extract a specific file from the .pkg:
    gunzip -c /path/to/XXX.pkg/Contents/Archive.pax.gz | pax -r -s ":old-path:new-path:" "old-path-to-file"
    
    For example, I want to extract LOCKED_IM61_0093_07B.fd from the package. First, I need to find its full path inside the package using the following command:
    $ gunzip  -c /Volumes/iMac\ EFI\ Updater/iMacFirmwareUpdate.pkg/Contents/Archive.pax.gz | pax | grep LOCKED_IM61_0093_07B.fd
    ./Applications/Utilities/iMac EFI Firmware Update.app/Contents/Resources/LOCKED_IM61_0093_07B.fd
    
    then I can run the following command to extract it from the package to the current directory:
    gunzip  -c /Volumes/iMac\ EFI\ Updater/iMacFirmwareUpdate.pkg/Contents/Archive.pax.gz | pax -r -s ":./Applications/Utilities/iMac EFI Firmware Update.app/Contents/Resources:.:" "./Applications/Utilities/iMac EFI Firmware Update.app/Contents/Resources/LOCKED_IM61_0093_07B.fd"
    

Mac OS X: mount or unmount .dmg image from command line

  • To mount a .dmg image in command line, run the following command in Terminal:
    hdiutil mount ~/Downloads/jdk-7u4-macosx-x64.dmg
    
    You will see something like below:
    $ hdiutil mount ~/Downloads/jdk-7u4-macosx-x64.dmg 
    expected   CRC32 $75F74818
    /dev/disk3           GUID_partition_scheme           
    /dev/disk3s1         Apple_HFS                       /Volumes/Oracle JDK 1.7.0_04
    
    It is mounted to "/Volumes/Oracle JDK 1.7.0_04"
  • To unmount it, run the following command in Terminal:
    hdiutil unmount "/Volumes/Oracle JDK 1.7.0_04"
    

明,清,民国对日宣战书见证国家兴衰

明朝平倭诏书

诏曰:
朕缵承洪绪,统理兆人,海澨山陬,皆我赤子,苟非元恶,普欲包荒。属者东夷小丑平秀吉,猥以下隶,敢发难端,窃据商封,役属诸岛。遂兴荐食之志,窥我内附之邦,伊歧对马之间,鲸鲵四起,乐浪玄菟之境,锋镝交加,君臣逋亡,人民离散,驰章告急,请兵往援。

朕念朝鲜,世称恭顺,适遭困厄,岂宜坐视,若使弱者不扶,谁其怀德,强者逃罚,谁其畏威。况东方为肩臂之藩,则此贼亦门庭之寇,遏沮定乱,在予一人。于是少命偏师,第加薄伐。平壤一战,已褫骄魂,而贼负固,多端阳顺阴逆,求本伺影,故作乞怜。册使未还,凶威复扇。朕洞知狡状,独断于心。乃发郡国羽林之材,无吝金钱勇爵之赏,必尽弁服,用澄海波。

仰赖天地鸿庥,宗社阴骘,神降之罚,贼殒其魁,而王师水陆并驱,正奇互用,爰分四路,并协一心,焚其刍粮,薄其巢穴。外援悉断,内计无之。于是同恶就歼,群酋宵遁,舳舻付于烈火,海水沸腾,戈甲积于高山,氛浸净扫,虽百年侨居之寇,举一旦荡涤靡遗。鸿雁来归,箕子之提封如故,熊罴振旅,汉家之德威播闻,除所获首功,封为京观,仍槛致平正秀等六十一人,弃尸稿街,传首天下,永垂凶逆之鉴戒,大泄神人之愤心。

于戏,我国家仁恩浩荡,恭顺者无困不援;义武奋扬,跳梁者虽强必戳。兹用布告天下,昭示四夷,明予非得已之心,识予不敢赦之意。毋越厥志而干显罚,各守分义以享太平。

凡我文武内外大小臣工,尚宜洁自爱民,奉公体国,以消萌衅,以导祯祥。更念彤力殚财,为日已久,嘉与休息,正惟此时,诸因东征加派钱粮,一切尽令所司除豁,务为存抚,勿事烦苛,咨尔多方,宜悉朕意。
万历二十七年闰四月丙戌,以平倭诏告天下。

清对日宣战书


朝鲜为我大清藩属,二百余年,岁修职贡,为中外所共知。近十数年,该国时多内乱,朝廷字小为怀,叠次派兵前往戢定,并派员驻扎该国都城,随时保护。本年四月间,朝鲜又有土匪变乱,该国王请兵援剿,情词迫切,当即谕令李鸿章拨兵赴援,甫抵牙山,匪徒星散。乃倭人无故派兵,突入汉城,嗣又增兵万余,迫令朝鲜更改国政,种种要挟,难以理喻。我朝抚绥藩服,其国内政事向令自理.日本与朝鲜立约,系属与国,更无以重兵欺压强令革政之理.各国公论,皆以日本师出无名,不合情理,劝令撤兵,和平商办.乃竟悍然不顾,迄无成说,反更陆续添兵.朝鲜百姓及中国商民,日加惊扰,是以添兵前往保护。讵行至中途,突有倭船多只,乘我不备,在牙山口外海面,开炮轰击,伤我运船。变诈情形,殊非意料所及。该国不遵条约,不守公法,任意鸱张,专行诡计,衅开自彼,公论昭然。用特布告天下,俾晓然于朝廷办理此事,实以仁至义尽,而倭人渝盟寻衅,无理已极,势难再以姑容。著李鸿章严饬派出各军,迅速进剿,厚集雄师,陆续进发,以拯韩民于涂炭。并著沿江沿海各将军督抚及统兵大臣,整饬戎行,遇有倭人轮船驶入各口,即行迎头痛击,悉数歼除,毋得稍有退缩,致干罪戾。将此通谕知之,钦此。

民国对日宣战书


日本军阀夙以征服亚洲、独霸太平洋为其国策国策。数年以来,中国不顾一切牺牲,继续抗战,其目的不仅所以保卫中国之独立生存,实欲打破日本侵略野心,维护国际公法、正义以及人类福利与世界和平。此中国屡经声明者。

中国为酷爱和平之民族,过去四年与之神圣抗战,原期侵略者之日本于遭受实际之惩创后,能反省。在此时各友邦亦极端忍耐,冀其悔祸,陴全太平洋之和平得以维持。不料残暴成性之日本,执迷不悟,且更悍然向我英美友邦开衅,扩大其战争侵略行为行动,甘为破坏全人类和平与正义之戎首,逞其侵略无厌职野心。举凡尊重信义之国家,咸属忍无可忍。兹特正式对日宣战,昭告中外,所有一切条约协定合同有涉及中日之间关系者,一律废止。特此有告。
:1931年9.18事变,日本占领东北三省。1937年7.7事变,日本全面侵华。1937年12月,日军南京大屠杀。而国民政府却直到1941年日军突袭珍珠港,太平洋战争全面爆发之后,才发此对日宣战书,正式对日宣战。

Proxy auto configuration example: proxy.pac

function FindProxyForURL(url, host) {
 if(isInNet(host, "198.168.0.0", "255.255.0.0") || 
    isInNet(host, "172.23.65.0", "255.255.255.0") || 
    isInNet(host, "127.0.0.0", "255.255.255.0") {
  return "DIRECT";
 } else {
  return "PROXY wwwproxy1.yourorg.org:3128; PROXY wwwproxy2.yourorg.org:3128; DIRECT";
 }
}

Shell script: arithmetic float point


  # 2/3
  echo "2/3" | bc -l


  # 0.67
  printf "%3.2f" $(echo "2/3" | bc -l)

SyntaxHighlighter on Blogger: how to enable border

Add the following style to your blog template, right after the SyntaxHighlighter css link:
<style type='text/css'>
    body .syntaxhighlighter {
        border: 1px dashed #808080;
        -webkit-border-radius: 3px;
        -moz-border-radius: 3px;
        -ms-border-radius: 3px;
        -o-border-radius: 3px;
        border-radius: 3px;
        max-height: 600px;
        overflow: auto;
        padding: 1px 1px 2px 2px;
    }
</style>

See also

Mac OS X Lion: Fix corrupt Mail folder

On Mac OS X Lion, it happened to me that the mail settings or messages were missing. Checked ~/Library/Mail folder, the messages are still there but I could not see them in Mac Mail. The solution for this is:
  • Quit your Mac Mail
  • Backup Mail folder:
    cp -r ~/Library/Mail /tmp/
    
  • Remove Envelope Index file:
    rm ~/Library/Mail/Envelope\ Index
    
  • Open Mac Mail application, it will import the messages automatically
  • Quit Mac Mail after import, then re-launch Mac Mail, you will see all the messages
  • Remove the backup if everything is ok:
    rm -fr /tmp/Mail
    

css: font families for programming (code)

.code, .pre {
   font-family: Terminus,Consolas,Profont,"Andale Mono",Monaco,Inconsolata,Inconsolata-g,
      Unifont,Lime,"ClearlyU PUA",Clean,"DejaVu Sans Mono","Lucida Console",
      "Bitstream Vera Sans Mono",Freemono,"Liberation Mono",Dina,Anka,Droid Sans Mono,
      Anonymous Pro,Proggy fonts,Envy Code R,Gamow,Courier,"Courier New",Terminal,monospace;
}

javascript: make base64 encoded string url friendly

based64 encoded string contains some characters that are not valid to be urls. The following javascript functions can be used to make a url safe string from a base64 encoded string.
function encodeURL(str){
    return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
}

function decodeUrl(str){
    str = (str + '===').slice(0, str.length + (str.length % 4));
    return str.replace(/-/g, '+').replace(/_/g, '/');
}

See also

Javascript: collapsable div





Source Code

<script type="text/javascript">
function update(){
    var button = document.getElementById("button1");
    var div = document.getElementById("div1");
    var action = button.value;
    if(action=="Show"){
        div.style.display='block';
        button.value = "Hide";
    } else if(action=="Hide"){
        div.style.display='none';
        button.value = "Show";
    }
}
</script>
<input id="button1" type="button" value="Show" onClick="update();"/><br/>
<div id="div1" style="background-color:#e0e0e0;display:none;">
Hi, there.<br/><br/><br/><br/><br/>
</div>

Javascript: base64 encoding and decoding

  • Method 1: use atob() and btoa() methods on Mozilla/Webkit based browsers.
  • Method 2: use the following javascript library:
  • Method 3: use jquery and jquery base 64 plugin.

See also

Make a bootable USB drive from the Windows 7 ISO image

  • Method 1: Use Windows 7 USB/DVD download tool (Download)
  • Method 2: Use WinToFlash (Download)
  • Method 3: Use bootsect tool from the Windows 7 Installation DVD/ISO
    1. Format the USB drive to FAT32.
    2. Copy/Extract the content of the Windows 7 ISO file to the USB drive.(You can use 7-ZIP to extract the iso file)
    3. Run the following command in Command Prompt to write the boot sector of the USB drive(assume the drive label is I:):
      I:\boot\bootsect /nt60 I:

Linux: list only directories

  • ls -d /home/wilson/*/
    
  • find /home/wilson/ -type d -maxdepth 1
    

Linux Check atime mtime ctime of a file or directory

  • On Linux:
    • Check atime (date time):
              stat -c %x 123.txt
            
              2012-08-10 13:22:16.414889863 +1000
            
    • Check atime (seconds):
              stat -c %X 123.txt
            
              1344568936
            
    • Check mtime (date time):
              stat -c %y 123.txt
            
              2012-08-10 13:22:16.414889863 +1000
            
    • Check mtime (seconds):
              stat -c %Y 123.txt
            
              1344568936
            
    • Check ctime (date time):
              stat -c %z 123.txt
            
              2012-08-10 13:22:16.414889863 +1000
            
    • Check ctime (seconds):
              stat -c %Z 123.txt
            
              1344568936
            

Find the file creation time on Linux

  1. Locate the partition where the file exists, for example, the file you want to check is /home/wilson/123.txt, you can run the following command to find the partition:
    mount
    /dev/sda1 on / type ext4 (rw)
    /dev/sda5 on /home type ext4 (rw)
    
  2. Run the following command:
    sudo debugfs -R 'stat /home/wilson/123.txt' /dev/sda5
    
    Inode: 1842342   Type: regular    Mode:  0644   Flags: 0x80000
    Generation: 2327791571    Version: 0x00000000:00000001
    User:  6000   Group:  6000   Size: 0
    File ACL: 0    Directory ACL: 0
    Links: 1   Blockcount: 0
    Fragment:  Address: 0    Number: 0    Size: 0
     ctime: 0x50247e68:62eade1c -- Fri Aug 10 13:22:16 2012
     atime: 0x50247e68:62eade1c -- Fri Aug 10 13:22:16 2012
     mtime: 0x50247e68:62eade1c -- Fri Aug 10 13:22:16 2012
    crtime: 0x50247e68:62eade1c -- Fri Aug 10 13:22:16 2012
    Size of extra inode fields: 28
    EXTENTS:
    
    where crtime is the file creation time.

Shell Script: conversion between seconds and dates

  • The following command gets current date/time in seconds:
    seconds=$(date +%s)
    
  • The following command formats seconds to specified date format:
    date -d @${seconds} +"%Y%m%d %H%:M:%S"
    

Shell: replace the shorten url with the real url

The shorten url are sometimes used to hide the real download url. With wget you can resolve the real url using --spider option:
$ wget --spider http://ligman.me/yZtVHF
Spider mode enabled. Check if remote file exists.
--2012-08-08 20:38:24--  http://ligman.me/yZtVHF
Resolving ligman.me... 69.58.188.49
Connecting to ligman.me|69.58.188.49|:80... connected.
HTTP request sent, awaiting response... 301 Moved
Location: http://download.microsoft.com/download/F/F/2/FF2EECEE-397A-45B9-83A4-821243F8DFFD/668836ebook.pdf [following]
Spider mode enabled. Check if remote file exists.
--2012-08-08 20:38:25--  http://download.microsoft.com/download/F/F/2/FF2EECEE-397A-45B9-83A4-821243F8DFFD/668836ebook.pdf
Resolving download.microsoft.com... 202.7.177.83, 203.26.28.162, 203.26.28.153, ...
Connecting to download.microsoft.com|202.7.177.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7564363 (7.2M) [application/octet-stream]
Remote file exists.


Improve the command a little bit, the command below filter out the url we need:
$ wget --spider http://ligman.me/yZtVHF 2>&1 | grep -o -E 'http[^"#]*' | tail -n 1
http://download.microsoft.com/download/F/F/2/FF2EECEE-397A-45B9-83A4-821243F8DFFD/668836ebook.pdf


If you have a html file contains many shorten urls, you can use the following comands to replace them with the real urls:
cat 1.html | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | sort | uniq > urls.txt
cat urls.txt | while read url1; do url2=$(wget --spider ${url1} 2>&1 | grep -o -E 'http[^"#]*' | tail -n 1); sed -i .bak 's|${url1}|${url2}|g' 1.html; done;
or the following script is more readable:
#!/bin/bash
cat 1.html | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | sort | uniq > urls.txt
cat urls.txt | while read url1
do
    url2=$(wget --spider ${url1} 2>&1 | grep -o -E 'http[^"#]*' | tail -n 1)
    sed -i .bak 's|${url1}|${url2}|g' 1.html
done

shell: extract urls from html file

cat 1.html | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | sort | uniq

shell script: for each line ...

  • IFS='\n'; for line in $(cat 1.txt); do echo $line; done; unset IFS
    
  • by piping cat:
    cat /path/to/file | while read line
    do
        echo $line
    done
    
  • by redirecting the file:
    while read line
    do
        echo $line
    done < /path/to/file
    
  • by using awk:
    awk '{print $0}' /path/to/file
    
  • by using head an tail:
    f=/path/to/file
    total=$(wc -l $f)
    n=0
    while [ $n -lt $total ]
    do
        let n++
        line=$(head -n $n $f | tail -1)
        echo ${line}
    done
    

sed: replace urls in a html file

  • The following command replaces all the url with http://www.example.com:
    sed 's|<a[^>]* href="[^"]*/|<a href="http://www.example.com|g'
    
  • The following command replaces http://123.com with http://456.com:
    sed 's|<a[^>]* href="[^"]http://123.com|<a href="http://456.com|g'
    

sed: delimiters for substitute strings

/ | % can be used as delimiters:
sed -i .bak -e 's/old/new/g' 1.txt
sed -i .bak -e 's%old%new%g' 2.txt
sed -i .bak -e 's|http://old.org|http://new.org|g' 3.html

Mac OS X: how to compile and install HTML tidy

  • First make sure you have xcode installed.
  • Check out source code from sourceforge (When asking for password, press enter):
    cvs -d:pserver:anonymous@tidy.cvs.sourceforge.net:/cvsroot/tidy login
    
    cvs -z3 -d:pserver:anonymous@tidy.cvs.sourceforge.net:/cvsroot/tidy co -P tidy
    
    
  • Configure:
    cd tidy; /bin/sh build/gnuauto/setup.sh
    
    ./configure --prefix=/usr/local
    
    
  • Compile then install:
    make
    
    sudo make install
    
    

Mac OS X: securely erase free space on a disk volume

  • Use Disk Utility in /Applications/Utilities
    • Select the volume you want to wipe free space, activate Erase tab, then click "Erase Free Space..." button:
    • Select the secure level then click Erase Free Space button:
  • Run diskutil in Terminal:
    diskutil secureErase freespace 1 "/Volumes/Macintosh HD"
    
    where 1 is the secure level. Below are the available levels:
    • 0 - Single-pass zeros.
    • 1 - Single-pass random numbers.
    • 2 - US DoD 7-pass secure erase.
    • 3 - Gutmann algorithm 35-pass secure erase.
    • 4 - US DoE 3-pass secure erase.

Note

The Mac OS Disk Utility (diskutil) does not wipe the file slacks. File slacks is the space after a file's data ends and until the file system block ends, and on a modern harddrive it can constitute gigabytes of data. Forensic investigators frequently find interesting information in file slack.

To wipe the free space as well as the file slacks, use BCWipe from Jetico.

wget: check if the file exists, but not download

--spider option can be used:

wget --spider <url>
you can use it to resolve the address: e.g.
$ wget --spider http://ligman.me/NyWB7H
Spider mode enabled. Check if remote file exists.
--2012-08-07 09:33:33--  http://ligman.me/NyWB7H
Resolving ligman.me... 69.58.188.49
Connecting to ligman.me|69.58.188.49|:80... connected.
HTTP request sent, awaiting response... 301 Moved
Location: http://download.microsoft.com/download/B/B/F/BBF0C6F3-6E36-4979-8C43-DE165AD7AE34/SP2010 Kerberos Guide.docx [following]
Spider mode enabled. Check if remote file exists.
--2012-08-07 09:33:34--  http://download.microsoft.com/download/B/B/F/BBF0C6F3-6E36-4979-8C43-DE165AD7AE34/SP2010%20Kerberos%20Guide.docx
Resolving download.microsoft.com... 203.13.161.16, 203.13.161.17
Connecting to download.microsoft.com|203.13.161.16|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7594191 (7.2M) [application/octet-stream]
Remote file exists.


You can also run it with -q option (quiet mode).
wget --spider http://ligman.me/NyWB7H
echo $?
If it returns 0 means the file exists. Non zero value means the file does not exist.

wget: how to limit download speed?

wget --limit-rate=100k <url>

Large Collection of Free Microsoft eBooks


  1. Moving to Microsoft Visual Studio 2010 (VS2005 PDF, VS2005 XPS, VS2008 PDF, VS2008 XPS)
  2. Programming Windows 8 Apps (PDF)
  3. Programming Windows Phone 7 (PDF, EPUB, MOBI)
  4. Programming Windows Phone 7 (Special Excerpt 2) (PDF)
  5. Office 365 Connect and Collaborate virtually anywhere, anytime (PDF, EPUB, MOBI)
  6. Microsoft Office 2010 First Look (PDF, XPS)
  7. Security and Privacy for Microsoft Office 2010 Users (PDF, EPUB, MOBI)
  8. Getting started with Microsoft Office 2010 - For IT Professionals (PDF, MOBI, DOC, XPS)
  9. Planning guide for Microsoft Office 2010 - For IT professionals (DOC, PDF, XPS)
  10. Deployment guide for Microsoft Office 2010 - For IT professionals (DOC, PDF, XPS)
  11. Operations guide for Microsoft Office 2010 - For IT professionals (DOC, PDF, XPS)
  12. Technical reference for Microsoft Office 2010 - For IT professionals (DOC, PDF, XPS)
  13. Understanding Microsoft Virtualization R2 Solutions (PDF, XPS)
  14. Introducing Windows Server 2012 (PDF, EPUB, MOBI)
  15. Introducing Microsoft SQL Server 2012 (PDF, EPUB, MOBI)
  16. Introducing Microsoft SQL Server 2008 R2 (PDF, XPS)
  17. Configure Kerberos Authentication for SharePoint 2010 Products (DOCX, PDF, EPUB, MOBI)
  18. Business continuity management for SharePoint Server 2010 (PDF, EPUB, MOBI)
  19. Deployment guide for SharePoint Server 2010 (PDF, EPUB, MOBI)
  20. Get started with SharePoint Server 2010 (PDF, EPUB, MOBI)
  21. Governance guide for Microsoft SharePoint Server 2010 (PDF, EPUB, MOBI)
  22. Profile synchronization guide for SharePoint Server 2010 (PDF, EPUB, MOBI)
  23. Remote BLOB storage for Microsoft SharePoint Server 2010 (PDF, EPUB, MOBI)
  24. Technical reference for Microsoft SharePoint Server 2010 (PDF, EPUB, MOBI)
  25. Upgrading to SharePoint Server 2010 (PDF, EPUB, MOBI)
  26. Getting Started with SharePoint Server 2010 (PDF, DOC, XPS, EPUB, MOBI)
  27. Planning guide for sites and solutions for Microsoft SharePoint Server 2010, Part 1 (PDF, DOC, XPS)
  28. Planning guide for sites and solutions for Microsoft SharePoint Server 2010, Part 2 (PDF, DOC, XPS)
  29. Planning guide for server farms and environments for Microsoft SharePoint Server 2010 (PDF, XPS, DOC)
  30. Capacity planning for Microsoft SharePoint Server 2010 (PDF, XPS, DOC)
  31. SQL Server 2012 Tutorials: Analysis Services - Tabular Modeling (PDF, EPUB, MOBI)
  32. Microsoft SQL Server AlwaysOn Solutions Guide for High Availability and Disaster Recovery (PDF, EPUB, MOBI)
  33. Transact-SQL Data Manipulation Language (DML) Reference (PDF, EPUB, MOBI)
  34. QuickStart: Learn DAX Basics in 30 Minutes (PDF, EPUB, MOBI)
  35. SQL Server 2012 Tutorials: Analysis Services - Data Mining (PDF, EPUB,MOBI)
  36. Microsoft SQL Server Analysis Services Multidimensional Performance and Operations Guide (PDF, EPUB, MOBI)
  37. Data Analysis Expressions (DAX) Reference (PDF, EPUB, MOBI)
  38. SQL Server 2012 Upgrade Technical Guide (PDF, EPUB, MOBI)
  39. Backup and Restore of SQL Server Databases (PDF, EPUB,MOBI)
  40. SQL Server 2012 Tutorials: Analysis Services - Multidimensional Modeling (PDF, EPUB, MOBI)
  41. Master Data Services Capacity Guidelines (PDF, EPUB, MOBI)
  42. Digital Storytelling
  43. Free Tools in the Classroom
  44. Windows Live Movie Maker in the Classroom
  45. Windows 7 in the Classroom
  46. Microsoft Office Web Apps Teaching Guide
  47. Microsoft Office in the Classroom
  48. Developing Critical Thinking through Web Research Skills
  49. Bing in the Classroom
  50. Moving Applications to the Cloud, 2nd Edition (PDF, EPUB,MOBI)
  51. Windows Azure Prescriptive Guidance (PDF, EPUB, MOBI)
  52. Windows Azure Service Bus Reference (PDF, EPUB, MOBI)
  53. Intro to ASP.NET MVC 4 with Visual Studio (Beta) (PDF, EPUB, MOBI)
  54. Deploying an ASP.NET Web Application to a Hosting Provider using Visual Studio (PDF, EPUB, MOBI)
  55. Getting Started with ASP.NET 4.5 Web Forms (Beta) (PDF, EPUB, MOBI)
  56. Introducing ASP.NET Web Pages 2 (PDF, EPUB, MOBI)
  57. Own Your Future (PDF, XPS)
  58. Windows 7 Power Users Guide)
  59. Deploying Windows 7 Essential Guidance (PDF)
  60. Welcome to Windows 7)
  61. What You Can Do Before You Call Tech Support (Windows 7) (PDF, XPS)
  62. Developing an Advanced Windows Phone 7.5 App that Connects to the Cloud
  63. Developing Applications for the Cloud, 2nd Edition
  64. Building Hybrid Applications in the Cloud on Windows Azure
  65. Building Elastic and Resilient Cloud Applications - Developer's Guide to the Enterprise Library 5.0 Integration Pack for Windows Azure (PDF, EPUB, MOBI)
  66. Technical reference for Microsoft SharePoint Server 2010
  67. Getting started with Microsoft SharePoint Foundation 2010
  68. Deployment guide for SharePoint 2013 Preview
  69. Deployment guide for Duet Enterprise for Microsoft SharePoint and SAP Server 2.0 Preview
  70. Microsoft Dynamics GP 2010 Guides: Financials
  71. Microsoft Dynamics CRM 2011 User's Guide
  72. Dynamics CRM 2011 Developer Training Kit
  73. Microsoft Dynamics CRM 2011 Implementation Guide
  74. Deployment guide for Office 2013 Preview
  75. Office 2010 Developer Training Kit
  76. Office 365 Developer Training Kit
  77. Office 365 Guides for professionals and small businesses
  78. Lync for Mac 2011 Deployment Guide
  79. Microsoft Lync Server 2010 Resource Kit Tools
  80. Microsoft Lync Server 2010 Resource Kit
  81. Microsoft Lync Server 2010 Security Guide
  82. Developing Applications for the Cloud – 2nd Edition
  83. Visual Studio LightSwitch Training Kit
  84. SQL Server 2012 Developer Training Kit
  85. Own Your Space--Keep Yourself and Your Stuff Safe Online Digital Book for Teens

Java: append string to a text file


public static void append(File f, String text) throws Throwable {
  BufferedWriter w; 
  try {
    w = new BufferedWriter(new FileWriter(f, true));
    w.write(text);
    w.flush();
  } finally {
    if(w!=null) {
      w.close();
    }
  }
}

Java ByteArrayOutputStream & ByteArrayInputStream: Streams in memory

Java ByteArrayOutputStream & ByteArrayInputStream are the stream in memory. For example, you can read a text file into memory using ByteArrayInputStream. See the example below:
    public static InputStream readFile(File f) throws Throwable {
        Reader r = new BufferedReader(new FileReader(f));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Writer w = new OutputStreamWriter(baos);
        char[] buffer = new char[2048];
        try {
            int n;
            while((n = r.read(buffer, 0, 2048))!=-1){
                w.write(buffer, 0, n);
            }
        } finally {
            r.close();
        }
        return new ByteArrayInputStream(baos.toByteArray());
    }

See also

Java: pipe OutputStream to InputStream

  • Method 1: use ByteArrayInputStream & ByteArrayOutputStream:
    
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    
        // write
        writeDataToOutputStream(baos);
        
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        
        // read
        readDataFromInputStream(bais);
    
    
  • Method 2: use PipedInputStream & PipedOutputStream:
    
        PipedInputStream pis = new PipedInputStream();
        PipedOutputStream pos = new PipedOutputStream(pis);
        // write
        writeDataToOutputStream(pos);
    
        // read
        readDataFromInputStream(pis);
    
    

See Also

Mac OS X: force empty trash in command line

Sometimes, the Mac Trash cannot be emptied.
You can run the following two commands in Terminal to empty your Trash:
  • The following command will empty the Trash in the user's home directory:
    rm -fr ~/.Trashes/*
    
  • The follwoing command will empty the Trashes on all the hard drives, e.g. on the external usb hard drive:
    IFS=$(echo -en "\n\b"); for d in $(ls /Volumes); do rm -fr /Volumes/$d/.Trashes/$UID/*; done; unset IFS
    

Handbrake for Mac: How to limit the CPU usage

When converting videos using Handbrake on Mac, the fans go crazy. Because audio/video encoding is cpu intensive and by default Handbrake uses all the cpus/cores. To limit the cpu usage in Handbrake:

  1. Activate Advanced tab
  2. Append
    :threads=1
    to the text area at the bottom of the tab






















Note

You can increase the number of threads to suit your needs: e.g.
:threads=2
if you have a quad-core mac.

Mac OS X: stop iMovie file import

Importing a file could take hours, I accidentally started importing a file. Could not find any option to stop it. Apple iMovie fail.
The only option left is Force Quit:
  • Option+Command+Esc
  • Hold
    Option+Shift+Command+Esc
    for 3 seconds (10.5+ only) to force quit the front-most application