Author Archives: cowman.chiang

[Java] Google authenticator

Reference: 1. Greddy’s Blogs: Google Authenticator實作 2. 菜鳥工程師 肉豬: Spring Boot 使用Google身分驗證器做TOTP驗證 Google Authenticator TOTP auth

Posted in Auth, Java | Comments Off on [Java] Google authenticator

[Java] Download file without saving

Source: CSDN: InputStream类available和read方法可能读取不到完整的流数据 stackoverflow: How to read a http file inmemory without saving on local drive? private static InputStream download(String sourceURL) throws Exception { InputStream inputStream = new URL(sourceURL).openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int … Continue reading

Posted in Java | Comments Off on [Java] Download file without saving

Line breaks issue

When we use command “ssh” with auto-completion, we get this error result. This is because we used the editor “sublime text” to edit the config before, which used the line endings of Windows. Then we can edit the setting of … Continue reading

Posted in Mac, Sublime Text 2, Sublime Text 3 | Comments Off on Line breaks issue

[VirtualBox] Host-only network is not working.

We can usually find the information about connecting to the Guest machine in VirtualBox. Most of the practices are performed using the Host-only setting method. But in version 7.0.4 of VirtualBox, the same setting does not work. This is because … Continue reading

Posted in Virtualbox | Comments Off on [VirtualBox] Host-only network is not working.

[Java] String with number format

Reference public static void main(String[] args) throws Exception { String number = “1000500000”; double amount = Double.parseDouble(number); DecimalFormat intFormatter = new DecimalFormat(“#,###”); DecimalFormat floatFormatter = new DecimalFormat(“#,###.00”); System.out.println(“==int==”); System.out.println(intFormatter.format(amount)); System.out.println(String.format(“%,d”, Integer.parseInt((number)))); System.out.println(number.replaceAll(“(\\d)(?=(\\d{3})+$)”, “$1,”)); System.out.println(“==float==”); System.out.println(floatFormatter.format(amount)); System.out.println(String.format(“%,.2f”, Float.parseFloat((number)))); } ==int== 1,000,500,000 … Continue reading

Posted in Java | Comments Off on [Java] String with number format

[Java] Mask some part of String

Reference: [stackoverflow] Mask some part of String return String.replaceAll(“\\b(\\d{3})\\d+(\\d{3})”, “$1****$2”); # 1234567890 => 123****890

Posted in Java | Comments Off on [Java] Mask some part of String

Trace URL request

Reference curl –trace-ascii – https://cowmanchiang.me/wp 0000: GET /wp HTTP/2 0010: Host: cowmanchiang.me 0027: user-agent: curl/7.79.1 0040: accept: */* 004d: == Info: Connection state changed (MAX_CONCURRENT_STREAMS == 128)! <= Recv header, 13 bytes (0xd) 0000: HTTP/2 301 <= Recv header, 15 … Continue reading

Posted in Network | Comments Off on Trace URL request

Mount remote folder over ssh on mac

Install sshfs Use brew (brew install sshfs) will get this error message, “Error: sshfs has been disabled because it requires FUSE!” Ref. https://github.com/telepresenceio/telepresence/issues/1654#issuecomment-1204676705 So download and install https://github.com/osxfuse/sshfs/releases/download/osxfuse-sshfs-2.5.0/sshfs-2.5.0.pkg Create local folder # mkdir mountFolder Mount remote folder # sshfs name@ssh_host:/path/to/folder … Continue reading

Posted in Mac | Comments Off on Mount remote folder over ssh on mac

RocksDB Tool

Install rocksdb first. brew install rocksdb Add alias in zshrc alias ldb = ‘rocksdb_ldb –db=. ‘ List all column families # ldb list_column_families Column families in .: {default, S1, User, C1, C2, U1, C3} Scan command: # ldb –column_family=User scan … Continue reading

Posted in RocksDB | Comments Off on RocksDB Tool

[Java] Append string with adaptive font size to image

Ref: https://blog.csdn.net/zengrenyuan/article/details/80281738 public static ByteArrayOutputStream encodeWithWaterMark(String content) { if (FRONT_IMAGE == null) { return encode(content); } ByteArrayOutputStream os = null; try { BitMatrix matrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, WIDTH, HEIGHT); BufferedImage backImage = QRCodeUtils.toBufferedImage(matrix); int fontSize = 20; String stringContent … Continue reading

Posted in Java | Comments Off on [Java] Append string with adaptive font size to image