Skip to content

Instantly share code, notes, and snippets.

View HoweChen's full-sized avatar
🎯
Focusing

Yuhao.Chen (Howe) - 陈雨豪 HoweChen

🎯
Focusing
View GitHub Profile
@HoweChen
HoweChen / round_half_up.py
Created April 12, 2019 05:31
[Python如何四舍五入]#Python
from decimal import Decimal, ROUND_HALF_UP
origin_num = Decimal('11.245')
answer_num = origin_num.quantize(Decimal('0.00'), rounding=ROUND_HALF_UP)
print(answer_num)
@HoweChen
HoweChen / save_restore_db.md
Created April 12, 2019 07:39
[Redis 保存和恢复数据库] #Redis

Redis 数据备份与恢复

Redis SAVE 命令用于创建当前数据库的备份。

语法

redis Save 命令基本语法如下:

redis 127.0.0.1:6379> SAVE 
@HoweChen
HoweChen / SyncManager.py
Last active June 25, 2019 15:17
[多进程共享嵌套class] #Python
from multiprocessing.managers import SyncManager
class PointClass:
def __init__(self, value):
self.value = value
class MathsClass:
def __init__(self, point_one, point_two):
@HoweChen
HoweChen / logger.py
Created August 20, 2019 03:20
[console和文件同时记录log]#Python
# setup the logging information
import datetime
today = datetime.today()
logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s %(message)s",
datefmt="%d-%M-%Y %H:%M:%S", level=logging.DEBUG, handlers=[
logging.FileHandler(filename=f"{today}.log"),
logging.StreamHandler()
])
logger = logging.getLogger()
logger.info("Test")
@HoweChen
HoweChen / mkdir_if_not_exist.py
Created August 21, 2019 02:56
[创建文件夹如果文件夹不存在]#Python
try:
# logs folder initialization
self.logs_path = Path("./logs")
self.logs_path.mkdir(exist_ok=True)
# repos folder initialization
self.repos_path = Path("./repos")
self.repos_path.mkdir(exist_ok=True)
# issues folder initialization
self.issues_path = Path("./issues")
self.issues_path.mkdir(exist_ok=True)
@HoweChen
HoweChen / App.java
Last active September 11, 2019 01:48
[Java 当中返回多个返回值]#Java
public class App
{
public static void main( String[] args )
{
TestService testService = new TestServiceImpl();
String name = "testName";
EnumMap<TestService.UserInfoProperty,Object> userInfo = testService.getUserInfoByName(name);
userInfo.entrySet().iterator();
System.out.println(userInfo.get(TestService.UserInfoProperty.Name));
System.out.println(userInfo.get(TestService.UserInfoProperty.ROOM));
@HoweChen
HoweChen / ArrayListInitialization.java
Created September 25, 2019 09:46
[ArrayList初始化] #Java
// traditional method
ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
// one-line method
ArrayList<String> list = new ArrayList<>(Arrays.asList("A","B","C"));
@HoweChen
HoweChen / queue2list.md
Created November 7, 2019 06:51
[Queue to List]#Java
List<?> list = new ArrayList<>( myQueue );

? can be be the class you want to transfer

@HoweChen
HoweChen / byte2HumanReadableSize.java
Created December 8, 2019 08:03
[文件大小转换byte to kb, mb, gb, pb, eb, zb ] #Java
public static strictfp String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
long absBytes = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes);
if (absBytes < unit) return bytes + " B";
int exp = (int) (Math.log(absBytes) / Math.log(unit));
long th = (long) (Math.pow(unit, exp) * (unit - 0.05));
if (exp < 6 && absBytes >= th - ((th & 0xfff) == 0xd00 ? 52 : 0)) exp++;
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
if (exp > 4) {
bytes /= unit;
@HoweChen
HoweChen / ListOperation.java
Created December 10, 2019 07:23
[Java List 交并差集运算] #Java
public class Test {
public static void main(String[] args) {
List<String> list1 = new ArrayList<String>();
list1.add("1");
list1.add("2");
list1.add("3");
list1.add("5");
list1.add("6");