小编vat*_*ale的帖子

具有确定(少量)变体的哈希/消化

我需要根据联系人姓名从字符串中获取16个(或其他少量)可能的哈希值,用于颜色编码联系人.

我曾尝试获取crc32哈希,然后取第一个符号,即十六进制数字:

$contact = 'Robin Hood';
$colors = [
     '0' => 'F8BBD0',
     '1' => 'E1BEE7',
     ...
     'e' => 'D7CCC8',
     'f' => 'CFD8DC',
];
$firstLetter = hash('crc32', $contact)[0];
return '#' . $colors[$firstLetter];
Run Code Online (Sandbox Code Playgroud)

但是,我怀疑这种方法的良好分布.如何从字符串中获取小的和确定数量的变体?

javascript php hash colors

7
推荐指数
1
解决办法
77
查看次数

如何将 ContinuationToken 与递归文件夹迭代器一起使用

由于 Drive API 配额、服务配额和脚本执行时间的限制,6 min将 Google Drive 文件操作拆分成块通常很重要。

我们可以用PropertiesService存储continuationTokenFolderIteratorFileIterator。这样我们就可以停止我们的脚本,并在下一次运行时从我们停止的地方继续。

工作示例(线性迭代器)

  // Logs the name of every file in the User's Drive
  // this is useful as the script may take more that 5 minutes (max execution time)
  var userProperties = PropertiesService.getUserProperties();
  var continuationToken = userProperties.getProperty('CONTINUATION_TOKEN');
  var start = new Date();
  var end = new Date();
  var maxTime = 1000*60*4.5; // Max safe time, 4.5 mins

  if (continuationToken == …
Run Code Online (Sandbox Code Playgroud)

google-apps-script google-drive-api

3
推荐指数
1
解决办法
3272
查看次数