Skip to content

Instantly share code, notes, and snippets.

View lndj's full-sized avatar
🎯
Focusing

Ning Luo lndj

🎯
Focusing
View GitHub Profile
@lndj
lndj / redis-rate-limiter.lua
Last active April 14, 2021 13:26
Redis 基于 lua 实现的令牌桶算法的限流器
local limit_info = redis.pcall('HMGET',KEYS[1],'last_time','curr_token')
local last_time = limit_info[1]
local curr_token = tonumber(limit_info[2])
local max_token = tonumber(ARGV[1])
local token_rate = tonumber(ARGV[2])
local offer_time = 1000/token_rate
-- 统一使用 redis 时间,避免多机器时间不一致问题 math.floor(x + 0.5)实现四舍五入
-- !!!不可以使用复制到 slave 之后操作结果不一致的命令出现,所以时间必须依赖传入
-- local time_info = redis.call('TIME')
-- local current_time = time_info[1]*1000+math.floor(time_info[2]/1000+0.5)

Python Socket 编程详细介绍

Python 提供了两个基本的 socket 模块:

  • Socket 它提供了标准的BSD Socket API。
  • SocketServer 它提供了服务器重心,可以简化网络服务器的开发。

下面讲解下 Socket模块功能。

Socket 类型

@lndj
lndj / chrome_extension_get_cookie.js
Created August 3, 2017 05:13 — forked from neekey/chrome_extension_get_cookie.js
Chrome 插件获取指定域下的Cookie,代码示例
@lndj
lndj / 01_Laravel 5 Simple ACL manager_Readme.md
Created March 12, 2016 10:03 — forked from amochohan/01_Laravel 5 Simple ACL manager_Readme.md
Laravel 5 Simple ACL - Protect routes by an account / role type

#Laravel 5 Simple ACL manager

Protect your routes with user roles. Simply add a 'role_id' to the User model, install the roles table and seed if you need some example roles to get going.

If the user has a 'Root' role, then they can perform any actions.

Installation

Simply copy the files across into the appropriate directories, and register the middleware in App\Http\Kernel.php