/images/avatar.png

linux删除百万级别文件

在运行任务时,往linux的同一个文件夹中写入超过500万个文件,导致在硬盘还有空间的情况下,在该文件夹下无法继续写入文件,也无法使用ls、rm等命令。记录处理过程。

Background: physical server, about two years old, 7200-RPM SATA drives connected to a 3Ware RAID card, ext3 FS mounted noatime and data=ordered, not under crazy load, kernel 2.6.18-92.1.22.el5, uptime 545 days. Directory doesn’t contain any subdirectories, just millions of small (~100 byte) files, with some larger (a few KB) ones.

We have a server that has gone a bit cuckoo over the course of the last few months, but we only noticed it the other day when it started being unable to write to a directory due to it containing too many files. Specifically, it started throwing this error in /var/log/messages:

Automatically Sort Data in Google Sheets

Automatically Sort Data in Google Sheets

Extension -> Apps script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function autoSort(e) {
  const ss = SpreadsheetApp.getActiveSpreadsheet()
  const ws = ss.getSheetByName("Sheet1")
  const range = ws.getRange(2,1,ws.getLastRow()-1,2)
  range.sort({column: 2, ascending: false})
}

function onEdit(e){
  autoSort(e)
}

Check SWAP

  1. Check SWAP used by differnt PID
1
for i in $(cd /proc;ls | grep "^[0-9]" | awk '$0>100'); do awk '/Swap:/{a=a+$2}END{print '"$i"',a/1024"M"}' /proc/$i/smaps;done| sort -k2nr | head
  1. Get the information about the PID
1
ps aux | grep ${pid}

xcode-select

显示“未能找到金属编译器安装的Xcode。请安装Xcode并运行Xcode.app来接受协议,或确保激活的开发者目录设为当前的Xcode安装(使用xcode-select)

解决方案:

1
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

lc1570. Dot Product of Two Sparse Vectors

给定两个稀疏向量,计算它们的点积(数量积)。

实现类 SparseVector:

SparseVector(nums) 以向量 nums 初始化对象。 dotProduct(vec) 计算此向量与 vec 的点积。 稀疏向量 是指绝大多数分量为 0 的向量。你需要 高效 地存储这个向量,并计算两个稀疏向量的点积。

进阶:当其中只有一个向量是稀疏向量时,你该如何解决此问题?

示例 1:

输入:nums1 = [1,0,0,2,3], nums2 = [0,3,0,4,0]

输出:8

解释:v1 = SparseVector(nums1) , v2 = SparseVector(nums2)

v1.dotProduct(v2) = 10 + 03 + 00 + 24 + 3*0 = 8

示例 2:

输入:nums1 = [0,1,0,0,0], nums2 = [0,0,0,0,2]

输出:0

解释:v1 = SparseVector(nums1) , v2 = SparseVector(nums2)

v1.dotProduct(v2) = 00 + 10 + 00 + 00 + 0*2 = 0