Search This Blog

Java: check if a String contains only ASCII

import java.nio.charset.Charset;

public boolean isAscii(String v) {
    Charset.forName("US-ASCII").newEncoder().canEncode(v);
}

Eclipse: Disable auto escaping when pasting

 

  1. In the preferences menu deselect: Java > Editor > Typing > Escape text when pasting into a string literal
  2. Disable smart insert mode: Edit > Smart Insert Mode [Ctrl+Shift+Insert]

Shell scripts to count files and sum up file sizes

#!/bin/sh
[ $# -ne 1 ] && echo "$(basename $0) <dir>" && exit 1
[ ! -d $1 ] && echo "$1 is not a directory." && exit 1
find "$1" -type f | wc -l
#!/bin/sh
[ $# -ne 1 ] && echo "$(basename $0) <dir>" && exit 1
[ ! -d $1 ] && echo "$1 is not a directory." && exit 1
if [ $(uname) == "Darwin" ]; then
find "$1" -type f -print0 | xargs -0 stat -f '%z ' | paste -sd+ - | bc
else
find "$1" -type f -printf %s\\n | paste -sd+ | bc
fi

Fix Windows 10 Update KB5034441 Error 0x80070643

The reason KB5034441 failed to install with error 0x80070643 is that there is not sufficient space in WinRE recovery partition. The solution is:

Manually resize your WinRE recovery partition by 250 MB

  1. Open a Command Prompt window (cmd) as Administrator.
  2. Check WindowsRE status:
    reagentc /info

    If the WinRE is installed, there should be a “Windows RE location” with a path to the WinRE directory. An example is, “Windows RE location: [file://%3f/GLOBALROOT/device/harddisk0/partition4/Recovery/WindowsRE]\\?\GLOBALROOT\device\harddisk0\partition4\Recovery\WindowsRE.” Here, the number after “harddisk” and “partition” is the index of the disk and partition WinRE is on.
  3. Disable the WindowsRE:
    reagentc /disable
  4. Shrink the OS partition and prepare the disk for a new recovery partition.
    • Run
      diskpart
    • Run
      list disk
    • Select the OS disk (This should be the same disk index as WinRE.), run
      sel disk OS_DISK_INDEX
      e.g.
      sel disk 0
      if disk 0 is the OS disk.
    • Find the OS Primary partition, run
      list part
    • Select the OS Primary partition, run
      sel part OS_PARTITION_INDEX
    • Shrink the OS Primary partition by 250MB, run
      shrink desired=250 minimum=250
  5. Delete the WinRE recovery partition
    • In diskpart, select WinRE partition, run
      sel part WinRE_PARTITION_INDEX
    • Delete the WinRE partition, run
      delete partition override
  6. Create a new WinRE recovery partition.
    • First, check if the disk partition style is a GUID Partition Table (GPT) or a Master Boot Record (MBR). To do that, run
      list disk
      . Check if there is an asterisk character (*) in the “Gpt” column. If there is an asterisk character (*), then the drive is GPT. Otherwise, the drive is MBR.
    • If your disk is GPT, run
      create partition primary id=de94bba4-06d1-4d40-a16a-bfd50179d6ac
      followed by the command
      gpt attributes =0x8000000000000001
    • If your disk is MBR, run
      create partition primary id=27
  7. Format the new WinRE recovery partition, run
    format quick fs=ntfs label="Windows RE tools"

    To confirm that the WinRE partition is created, run
    list vol

    Exit from diskpart, run
    exit
  8. Re-enable WinRE, run
    reagentc /enable

    To confirm where WinRE is installed, run
    reagentc /info

Now you should be able to install KB5034441 via Windows Update






See also