Skip to content

Instantly share code, notes, and snippets.

@ensky
ensky / zpopmin-zpopmax.lua
Last active June 8, 2020 13:10
redis zpopmin / zpopmax in lua for redis < 5.0.0
-- redis-priority-queue
-- Author: Ensky Lin
-- Version: 1.0.0
-- (can only be used in 3.2+)
-- Get mandatory vars
local action = ARGV[1];
local key = ARGV[2];
local count = ARGV[3];
check 1: | 7, 3 | 8, 5 | | 1, 9 |
check 2: | 6,12 | 3,10 | 5, 7 | 4, 2 |
check 3: | 11, 4 | 7, 6 | 3, 9 | | | 2, 8
check 4: | | 4, 1 | 2, 6 | 7, 8 | 3,12 | 5,11 | 10, 9
check 5: | | | 12,11 | | 8,10 | 1, 2 | 7, 4
check 6: | 1, 8 | 12, 9 | | 11,10 | 2, 7 | 3, 4 | 6, 5
check 7: | 10, 5 | 11, 2 | 4, 8 | 3, 6 | | 9, 7 | 12, 1
check 8: | 9, 2 | | 10, 1 | 5,12 | | 6, 8 | 3,11
Run Times: 19239411
Memory: 0 MB
@ensky
ensky / Blength.js
Created May 6, 2012 17:41
JS 中文字長度偵測
// 中文字會算長度2,英文字算長度1
String.prototype.Blength = function() {
var arr = this.match(/[^\x00-\xff]/ig);
return arr == null ? this.length : this.length + arr.length;
};