Skip to content

Instantly share code, notes, and snippets.

1、String[] array = new String[2];
2、String[] array = {"1", "2"};
3、String[] array = new String[]{"1", "2"};
以上三种方式创建的数组,长度都是2,第二种和第三种已经设置了值。
@HowieChih
HowieChih / ListToMap.java
Created September 19, 2024 03:15
Java List to Map with list element key
Map<Long, List<UserEntity>> userListMap = userEntityList.stream().collect(Collectors.groupingBy(UserEntity::getOrganizationId));
long millisInDay = 24 * 60 * 60 * 1000;
long tomorrowMidnight = (endTimestamp / millisInDay + 1) * millisInDay;
@HowieChih
HowieChih / hashmapAvoidContainsKey.java
Last active August 21, 2024 10:43
Java update value if key exists, or else create it
// the user
public Class User {
private String name;
}
// with containsKey
HashMap<Integer, User> map = new HashMap<>();
if (map.containsKey(100)) {
User user = map.get(100);
@HowieChih
HowieChih / wsl-distribution-list-location-size.ps
Created August 2, 2024 08:12
Get list of all WSL distributions, their locations, and sizes
Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" -Recurse |
ForEach-Object {
$distro_name = ($_ | Get-ItemProperty -Name DistributionName).DistributionName
$distro_dir = ($_ | Get-ItemProperty -Name BasePath).BasePath
$distro_dir = Switch ($PSVersionTable.PSEdition) {
"Core" {
$distro_dir -replace '^\\\\\?\\',''
}
"Desktop" {
@HowieChih
HowieChih / ConditionExec.java
Created May 11, 2024 06:29
从NVM安装脚本里学了一招写if...else...的操作
public class ConditionExec {
public static void main(String[] args) {
ConditionExec exec = new ConditionExec();
if (args.length == null) {
exec.doAlpha();
} else {
exec.doBeta();
}
@HowieChih
HowieChih / infoForm.js
Created October 23, 2019 09:21
React Form Sample
import React from 'react';
class InfoForm extends React.Component {
constructor(props) {
super(props);
this.state = {
name: '',
gender: 'female',
languages: [],
nation: ''
package com.foo;
import java.util.Calendar;
import java.util.Date;
public class CustomDateUtils {
/**
* 根据生日计算年龄
*

Problem

The default encoding is system code page in Internet Explorer of URL's query string. It will make some errors when server side receive the query string with encoding UTF-8.

Solution

Encoding the query string to UTF-8 with JavaScript window.encodeURIComponent(str) before request send.

Example

location.href = 'http://www.example.com/search?key=' + window.encodeURIComponent('文');
package com.ihouse.controller;
interface InterfaceA {
Number getNumber();
}
interface InterfaceB {
Integer getNumber();
}