Skip to content

Instantly share code, notes, and snippets.

View CandyMi's full-sized avatar

CandyMi CandyMi

View GitHub Profile
@CandyMi
CandyMi / uuid.c
Last active October 20, 2022 15:08
UUID 1-5 实现
/*
** LICENSE: BSD
** Author: CandyMi[https://github.com/candymi]
*/
#include "lcrypto.h"
#define GUID_LENGTH 35
int lguid(lua_State *L) {
const uint8_t* hash = (const uint8_t*)luaL_checkstring(L, 1);
@CandyMi
CandyMi / README.md
Last active August 22, 2022 07:30
Lua的C库模版生成脚本

安装

  1. 安装任意版本的lua或者luajit.

  2. clib.lua放置在/usr/bin或者/usr/local/bin下.

  3. 使用chmod +x clib.lua为其添加可执行权限.

  4. 完成

@CandyMi
CandyMi / demo.c
Created July 7, 2022 17:14
测试指令集在不同优化等级下生成汇编代码对比
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#if defined(__AVX__)
#include <immintrin.h>
#endif
#if defined(__SSE2__)
@CandyMi
CandyMi / demo.c
Last active December 29, 2022 08:06
基于 intel sse4指令集的crc32c实现
#include <stdint.h>
#if defined(__x86_64__) || defined(__i386__)
static inline uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v) {
__asm__ volatile("crc32b %1, %0" : "+r"(crc) : "rm"(v));
return crc;
}
static inline uint32_t _mm_crc32_u16(uint32_t crc, uint16_t v) {
__asm__ volatile("crc32w %1, %0" : "+r"(crc) : "rm"(v));

最小连接数算法

Lua 实现

local toint = math.tointeger

local tsort = table.sort

local class = require "class"
@CandyMi
CandyMi / README.md
Last active December 5, 2021 17:11
Lua、python、js根据Nilakantha级数计算Pi的近似值.

介绍

Nilakantha 级数:

  1. 从3开始依次交递加、减以4为分子、三个连续整数乘积为分母的分数.
  2. 每次迭代时3个连续整数中的最小整数是上次迭代时三个整数中的最大整数。
  3. 然后经过反复计算10万次,则可以得到精确到小数点后12位的Pi近似值.
@CandyMi
CandyMi / README.md
Last active December 5, 2021 13:30
对Lua、js、Python等脚本语言浮点数运算进行简单性能测试.

简单的浮点数运算示例

CPU 主频
i5-10400 2.9GHz
  • CPU - i5-10400 2.9GHz

  • OS - Linux

@CandyMi
CandyMi / set.lua
Last active October 16, 2021 19:00
Lua 数据结构实现
local type = type
local pairs = pairs
local assert = assert
local tostring = tostring
local setmetatable = setmetatable
local tconcat = table.concat
---@class Set @集合
local MetaSet = { map = {} }
@CandyMi
CandyMi / README.md
Last active August 19, 2021 09:49
Linux 下的 SQL Server 安装

硬件要求

  1. CentOS(RHEL) 7+ 以上系统;

  2. 至少1C2G以上;

yum 安装

  1. 这里找到自己想要安装的版本的.repo文件;
@CandyMi
CandyMi / README.md
Last active August 16, 2021 06:48
浏览器自动化测试