Skip to content

Instantly share code, notes, and snippets.

View GloryAlex's full-sized avatar

GloryAlex

View GitHub Profile
@GloryAlex
GloryAlex / Check for epoll.java
Last active December 9, 2022 13:47
Mac OS不提供epoll方法,本机测试的话用kqueue
final boolean isMac =
System.getProperty("os.name").toLowerCase(Locale.US).contains("mac");
// Configure the server.
// See https://netty.io/wiki/native-transports.html
EventLoopGroup bossGroup;
EventLoopGroup workerGroup;
if (isMac) {
bossGroup = new io.netty.channel.kqueue.KQueueEventLoopGroup();
workerGroup = new io.netty.channel.kqueue.KQueueEventLoopGroup(5);
} else {

首先要连接数据库:

mysql --local-infile -u root -p DATABASE

这里要注意加上关键词 --local-infile,否则会报 Loading local data is disabled 错误。 然后使用指令

  LOAD DATA infile '/src/test.csv' --CSV文件存放路径
  INTO TABLE student--要将数据导入的表名
  FIELDS TERMINATED BY ',' 
@GloryAlex
GloryAlex / 操作ByteBuf.java
Created June 26, 2021 14:17
Bytebuf有几种不同的操作模式
ByteBuf buf = ...// get ByteBuf
int length = buf.readableBytes();//get readable length
if(buf.hasArray()){
//ByteBuf in heap
byte[] array = buf.array();
int offset = buf.arrayOffset()+buf.readerIndex();
handleArray(array,offset,length);//your method
}else{
//ByteBuf in direct buffer
byte[] array=new byte[length];

ByteBuf本质上是一个字节数组,但根据存放位置不同,它有几种不同的操作模式。

堆缓冲区

数据存储在JVM的堆空间内。此时可以直接操作数据。

ByteBuf buf = ...// get ByteBuf
if(buf.hasArray()){
    //ByteBuf in heap
    byte[] array = buf.array();
    int length = buf.readableBytes();//get readable length
 int offset = buf.arrayOffset()+buf.readerIndex();
@GloryAlex
GloryAlex / Servlets 中文编码.java
Last active December 9, 2022 13:45
乱码的话设置下html头
resp.setContentType("text/html;charset=UTF-8");
@GloryAlex
GloryAlex / GLOB模式小结.md
Last active November 26, 2021 07:15
所谓的 glob 模式是指 shell 所使用的简化了的正则表达式。

元字符

元字符 说明
* 匹配除了斜杠(/)之外的所有字符。Windows上是斜杠(/)和反斜杠(\)
** 匹配零个或多个目录及子目录。不包含 . 以及 .. 开头的。
? 匹配任意单个字符。
[seq] 匹配 seq 中的其中一个字符。
[!seq] 匹配不在 seq 中的任意一个字符。
\ 转义符。
@GloryAlex
GloryAlex / 二分搜索.py
Created April 20, 2022 06:55
标准库的实现
# 求左闭右开非降序区间 [left, right) 中第一个大于或等于 target 的位置
def lower_bound(array, left, right, target):
while left < right:
mid = left + (right - left) // 2 # 防止溢出
if array[mid] < target: left = mid + 1
# if !(target < array[mid]): # 小于等于即为 upper_bound
else: right = mid
return left # 此时 left==right 成立
@GloryAlex
GloryAlex / Preview in Marked 2.py
Last active May 29, 2024 08:09
CotEditor Script
#!/usr/bin/env python3
# %%%{CotEditorXInput=AllText}%%%
# %%%{CotEditorXOutput=Discard}%%%
import sys
import urllib.parse
import webbrowser
content = sys.stdin.read()
content = urllib.parse.quote(content)