Java: encode string to URI string (raw encode)








package test;

import java.net.URI;
import java.net.URL;

public class URIEncoder {

    public static String encode(String url) throws Exception {
        URL urlObj = new URL(url);
        URI uriObj = new URI(urlObj.getProtocol(), urlObj.getUserInfo(), urlObj.getHost(), urlObj.getPort(), urlObj.getPath(),
                urlObj.getQuery(), urlObj.getRef());
        return uriObj.toString();
    }

}

See also




Create a bootable usb stick from ISO file on Mac OS X








  1. Have your bootable .iso image file ready
  2. Open the Terminal (in /Applications/Utilities/ or query Terminal in Spotlight).
  3. Convert the .iso file to .img using the convert option of hdiutil e.g.,
    hdiutil convert -format UDRW -o ~/path/to/debian.img ~/path/to/debian.iso
    mv ~/path/to/debian.img.dmg ~/path/to/debian.img

    Note: OS X tends to put the .dmg ending on the output file automatically.
  4. Run
    diskutil list
    to get the current list of devices.
  5. Insert your usb stick.
  6. Run
    diskutil list
    again and determine the device node assigned to your flash media (e.g. /dev/disk2).
  7. Run
    diskutil unmountDisk /dev/diskN
    (Note:replace N with the disk number from the last command; in the previous example, N would be 2).
  8. Execute
    sudo dd if=/path/to/debian.img of=/dev/rdiskN bs=1m
    (replace /path/to/debian.img with the path where the image file is located).
    Note:Using /dev/rdisk instead of /dev/disk may be faster.
    If you see the error dd: Invalid number '1m', you are using GNU dd. Use the same command but replace bs=1m with bs=1M
    If you see the error dd: /dev/diskN: Resource busy, make sure the disk is not in use. Start the 'Disk Utility.app' and unmount (don't eject) the drive.
  9. Run
    diskutil eject /dev/diskN
    and remove your flash media when the command completes.
  10. Restart your Mac and press alt/option key while the Mac is restarting to choose the USB stick.



git: ignore .DS_Store files globally















git config --global core.excludesfile ~/.gitignore
echo ".DS_Store" >> ~/.gitignore










Linux: find files by date








  • Find files modified between 2013-01-01 and 2013-12-31:
    touch --date "2013-01-01" /tmp/start
    touch --date "2013-12-31" /tmp/end
    find /data/images -type f -newer /tmp/start -not -newer /tmp/end
  • Find .sh files accessed 7 days ago:
    find ~ -iname "*.sh" -atime -7 -type -f



Disable auto correct spelling in Safari





















From the top menu bar, select "Edit" -> "Spelling and grammar" -> uncheck "Correct spelling automatically"















GWT: extract protocol and host from url








AnchorElement anchor = Document.get().createAnchorElement();
anchor.setHref("http://youdomain.org/path/");
String protocol = anchor.getPropertyString("protocol");
String host = anchor.getPropertyString("host");
String path = anchor.getPropertyString("pathname");
anchor.removeFromParent();



Eclipse shortcut key combos












Coolpad 大神 F1 8297W安装Google 应用商店








  • 1. 下载presetgms-Coolpad 8297W.zip
  • 2. 将下载后的文件置于 /storage/emulated/0 目录。(注意: 文件名必须是 presetgms-Coolpad 8297W.zip,中间有一个空格。
  • 3. 进入系统设置—关于手机,连续点击8次"版本号",进入开发者模式,即按返回键退出关于手机能够看到"开发者选项";
  • 4. 点击进入开发者选项,下拉到最后面找到“GMS包预安装”选项,点击,系统提示“将重启手机进行GMS包安装”,点击确定进行安装;
  • 5. 安装完成后,会自动开机,开机完成进入应用即可查看到安装的GMS包应用
  • 6. 到Coolpad自带应用商店更新Google Play应用,之后就可以从Google Play应用商店安装应用

See also




Java: check your external ip (conditions apply)








import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class IpChecker {

    public static String getIp() throws Exception {
        URL whatismyip = new URL("http://checkip.amazonaws.com");
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(
                    whatismyip.openStream()));
            String ip = in.readLine();
            return ip;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

see also

  • http://stackoverflow.com/questions/2939218/getting-the-external-ip-address-in-java



eclipse annotation: @SuppressWarnings








To suppress single type of warnings:
@SuppressWarnings("unchecked")

To suppress multiple types of warnings:
@SuppressWarnings({"unused", "unchecked"})



Stop Safari from unzipping the downloaded archive files








Safari -> Preferences -> General -> uncheck "Open "safe" files after downloading"



Five Lies That Could Be Ruining Your Career (and your Life)








1) I haven’t found my passion / I don’t have a passion.
2) I can’t afford to leave the job I don’t like.
3) It’s too late to change direction now.
4) Pursuing my own happiness is selfish. I have a family to think about.
5) I hate my job now, but I will be happy as soon as I [get the promotion/finish the project/collect my bonus/get my degree]


by Theresa Sullivan