import java.nio.charset.Charset;
public boolean isAscii(String v) {
Charset.forName("US-ASCII").newEncoder().canEncode(v);
}
Search This Blog
Java: check if a String contains only ASCII
Eclipse: Disable auto escaping when pasting
- In the preferences menu deselect: Java > Editor > Typing > Escape text when pasting into a string literal
- Disable smart insert mode: Edit > Smart Insert Mode [Ctrl+Shift+Insert]
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
- Open a Command Prompt window (cmd) as Administrator.
- 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. - Disable the WindowsRE:
reagentc /disable
- 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
- Run
- Delete the WinRE recovery partition
- In diskpart, select WinRE partition, run
sel part WinRE_PARTITION_INDEX
- Delete the WinRE partition, run
delete partition override
- In diskpart, select WinRE partition, run
- 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 commandgpt attributes =0x8000000000000001
- If your disk is MBR, run
create partition primary id=27
- First, check if the disk partition style is a GUID Partition Table (GPT) or a Master Boot Record (MBR). To do that, run
- Format the new WinRE recovery partition, run
format quick fs=ntfs label="Windows RE tools"
To confirm that the WinRE partition is created, runlist vol
Exit from diskpart, runexit
- Re-enable WinRE, run
reagentc /enable
To confirm where WinRE is installed, runreagentc /info
Now you should be able to install KB5034441 via Windows Update
See also
Compress sparse files preserving their holes
use -S option for tar
tar -Sczvf sparse_file.tar.gz sparse_file
Find sparse files in Linux
find ./ -type f -printf "%S\t%p\n" | awk '$1 < 1.0 {print}'
find ./ -type f -printf "%S\t%p\n" | awk '$1 < 1.0 {print $2}'To find and remove the sparse files:
find ./ -type f -printf "%S\t%p\n" | awk '$1 < 1.0 {print $2}' | xargs rm -fTo find and compress the sparse files:
find ./ -type f -printf "%S\t%p\n" | awk '$1 < 1.0 {print $2}' | xargs -I {} sh -c "tar -Sczvf {}.tar.gz {}; rm -f {}"Excel custom formatting cells for file sizes (GB and TB)
[<1000000]0.00," KB";[<1000000000]0.00,," MB";0.00,,," GB"
[<1000000000]0.00,," MB";[<1000000000000]0.0,,," GB";0.0,,,," TB"
SSH public key authentication rejected with debug message: no mutual signature algorithm
ssh user@remote-server -vvvv
debug1: no mutual signature algorithm
Cause
The RSA SHA-1 hash algorithm is being quickly deprecated across operating systems and SSH clients because of various security vulnerabilities, with many of these technologies now outright denying the use of this algorithm.
Solution
Generate SSH key using ED25519 algorithm:ssh-keygen -t ed25519
See also
Install RSAT Active Directory Administrative Center on Windows 10 (22H2)
Run PowerShell as Administrator and paste the commands below:
$currentWU = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" | select -ExpandProperty UseWUServer
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" -Value 0
Restart-Service wuauserv
Get-WindowsCapability -Name Rsat.ActiveDirectory.DS-LDS.Tools -Online | Add-WindowsCapability –Online
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" -Value $currentWU
Restart-Service wuauserv
see also
Java: remove unsafe html tags
public class HtmlTagRemover {
public static String removeUnsafeTags(String html) {
// Define the regular expression pattern to match unsafe tags
String unsafeTagsPattern = "<(script|iframe|object|embed)[^>]*>.*?</\\1>";
// Remove the unsafe tags from the HTML string
String safeHtml = html.replaceAll(unsafeTagsPattern, "");
return safeHtml;
}
public static void main(String[] args) {
String html = "<b>Safe HTML</b><script>alert('XSS')</script>";
String safeHtml = removeUnsafeTags(html);
System.out.println(safeHtml);
}
}
Install pre-requisites for flake8 (python language server) on Linux
- Install pip:
sudo apt install python3-pip - Check python version:
python3 --versionPython 3.10.6 - Install virtualenv:
sudo apt install python3.10-virtualenv
My zsh prompt setup
Add following line to ~/.zshrc:
More details about ZSH prompt: https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
PROMPT='%F{red}%*%f %F{blue}%1~%f %# '
More details about ZSH prompt: https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
Setup Neovim and LazyVim
I. Install Neovim
- Download nightly build from https://github.com/neovim/neovim/releases/tag/nightly
- Alternatively, build from source: https://github.com/neovim/neovim/wiki/Building-Neovim
II. Install LazyVim
- Follow the instructions to install LazyVim: https://www.lazyvim.org/installation
- Install fd, ripgrep, fzf, lazygit:
- Mac OS:
brew install fd ripgrep fzf lazygit - Linux:
apt install fd-find ripgrep fzf lazygit
- Mac OS:
III. Configuration
- Install toggleterm.nvim. Create file: ~/.config/nvim/lua/plugins/toggleterm.lua:
-- ~/.config/nvim/lua/plugins/toggleterm.lua return { { "akinsho/toggleterm.nvim", tag = "2.4.0", keys = { { "<leader>th", "<cmd>ToggleTerm size=15 direction=horizontal<cr>", desc = "Open a horizontal terminal" }, { "<leader>tt", "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" }, { "<F7>", "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" }, { "<F7>", "<cmd>ToggleTerm<cr>", mode= "t", desc = "Toggle terminal" }, }, opts = { --[[ things you want to change go here]] }, }, } - Set options in ~/.config/nvim/lua/config/options.lua:
-- ~/.config/nvim/lua/config/options.lua vim.opt.relativenumber = false -- Relative line numbers vim.opt.shiftwidth = 4 -- Size of an indent vim.opt.tabstop = 4 -- Number of spaces tabs count for - Install nightfox colorscheme. Create file: ~/.config/nvim/lua/plugins/colorscheme.lua:
-- ~/.config/nvim/lua/plugins/colorscheme.lua return { -- add nightfox colorscheme { "EdenEast/nightfox.nvim" }, -- Configure LazyVim to load nightfox { "LazyVim/LazyVim", opts = { colorscheme = "carbonfox", }, } }
See also
Mac OS: fix duplicated Open With entries
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user;killall Finder;echo "Open With has been rebuilt, Finder will relaunch"
see also
Compile Neovide from source on Mac OS
- Install the latest version of Rust.
- Install CMake. Using homebrew:
brew install cmake - Check out the source code:
git clone https://github.com/neovide/neovide - Compile and install the binary: neovide into ~/.cargo/bin:
The resulting binary is to be found under ~/.cargo/bin.cd neovide cargo install --path . - In case you want a nice application bundle:
Copy ./target/release/bundle/osx/neovide.app to ~/Applications and enjoy.cargo install cargo-bundle cargo bundle --release
See also
NeoVim: Clean Up Everything (Config, Plugins, Cache ...)
# linux/macos (unix)
rm -rf ~/.config/nvim
rm -rf ~/.local/share/nvim
rm -rf ~/.local/state/nvim
rm -rf ~/.cache/nvim
# windows
rd -r ~\AppData\Local\nvim
rd -r ~\AppData\Local\nvim-data
see also
Use GNU grep to count the length of substring between two words
Note: the command below requires GNU grep, it is available on Linux by default. On Mac OS, you need to install it manually using
Output should be:
Output should be:
brew install grep and command is called ggrep instead of grep.
Get the substring between two words
echo "<person><name>abc</name></person>" | grep -o -P '(?<=<name>).*(?=</name>)'Output should be:
abc
Count the length of substring
echo "<person><name>abc</name></person>" | grep -o -P '(?<=<name>).*(?=</name>)' | wc -cOutput should be:
3
Count substring lengths for each line
cat multi-lines.txt | while read line; do echo $line | grep -o -P '(?<=<name>).*(?=</name>)' | wc -c; donesee also
Subscribe to:
Posts (Atom)