Skip to content

Instantly share code, notes, and snippets.

View stoensin's full-sized avatar
🎯
Focusing

Joe Stone stoensin

🎯
Focusing
  • shenzhen university
  • shenzhen
View GitHub Profile
@stoensin
stoensin / cosine_similarity.js
Created December 26, 2023 05:15 — forked from tomericco/cosine_similarity.js
Cosine similarity implementation in JS
const str1 = 'This is an example to test cosine similarity between two strings';
const str2 = 'This example is testing cosine similatiry for given two strings';
//
// Preprocess strings and combine words to a unique collection
//
const str1Words = str1.trim().split(' ').map(omitPunctuations).map(toLowercase);
const str2Words = str2.trim().split(' ').map(omitPunctuations).map(toLowercase);
const allWordsUnique = Array.from(new Set(str1Words.concat(str2Words)));
@stoensin
stoensin / sha256-hmac.md
Created December 14, 2022 10:25 — forked from jasny/sha256-hmac.md
Hashing examples in different languages

Example inputs:

Variable Value
key the shared secret key here
message the message to hash here

Reference outputs for example inputs above:

| Type | Hash |

from __future__ import division
import json
import lightgbm as lgb
import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error
from sklearn.linear_model import LogisticRegression
# load or create your dataset
print('Load data...')
from sklearn.model_selection import cross_val_score
cross_val_score(model, X, y=None, scoring=None, cv=None, n_jobs=1)
"""参数
---
model:拟合数据的模型
cv : k-fold
scoring: 打分参数-‘accuracy’、‘f1’、‘precision’、‘recall’ 、‘roc_auc’、'neg_log_loss'等等
"""
# 检验曲线
from sklearn.preprocessing import StandardScaler
#标准化,返回值为标准化后的数据
StandardScaler().fit_transform(iris.data)
from sklearn.preprocessing import MinMaxScaler
#区间缩放,返回值为缩放到[0, 1]区间的数据
MinMaxScaler().fit_transform(iris.data)
from sklearn.preprocessing import Normalizer
#归一化,返回值为归一化后的数据
@stoensin
stoensin / readspace.cpp
Last active June 30, 2021 12:05
getline(cin, inputLine);函数,接受一个字符串的输入包含空格,遇到回车停止要包含 #incldue<string> ,一般用来读取用string类存储表示的字符串。 很多程序中,可能会碰到ofstream out("Hello.txt"), ifstream in("..."),fstream foi("...")这样的的使用,并没有显式的去调用open()函数就进行文件的操作,直接调用了其默认的打开方式,因为在stream类的构造函数中调用了open()函数,并拥有同样的构造函数,所以在这里可以直接使用流对象进行文件的操作
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
// 读取文件 文件每一行是空格分隔开的图片像素值 每行1000个值
int main()
{
ifstream infile_feat(loadFeatList); //加载数据文件路径,获取到流对象infile_feat

C 标准库 - <stdio.h>

简介

stdio .h 头文件定义了三个变量类型、一些宏和各种函数来执行输入和输出。

库变量

下面是头文件 stdio.h 中定义的变量类型:

@stoensin
stoensin / README.md
Created June 28, 2021 10:12
CM变量 指令等

CMakeLists 详解

CMakeLists 变量篇

我们可以使用 SET(set) 来定义变量

语法SET(VAR [VALUE] [CACHE TYPE DOCSTRING [FORCE]]) 指令功能 : 用来显式的定义变量 例子 : SET (SRC_LST main.c other.c) 说明: 用变量代替值,例子中定义 SRC_LST 代替后面的字符串。

@stoensin
stoensin / f
Last active December 23, 2020 07:45
循环缓冲区对于数据写入和读出以不同速率发生的情况也是非常有用的结构:最新数据始终可用。如果读取数据的速度跟不上写入数据的速度,旧的数据将被新写入的数据覆盖。通过使用循环缓冲区,能够保证我们始终使用最新的数据。 环形缓冲区在处理异步IO时非常实用。它们可以在一端接收随机长度和区间的数据,在另一端以相同长度和区间提供密致的数据块。它们是Queue数据结构的变体,但是它针对于字节块而不是一系列指针。
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//must be a power of two so when B fit this: A % B == A &(B - 1)
#define RING_SIZE (32U)
#define RING_MASK (RING_SIZE - 1)
//将普通索引转换成ring_buf的索引
@stoensin
stoensin / sunday.c
Last active December 22, 2020 13:22
Sunday算法其实思想跟BM算法很相似,只不过Sunday算法是从前往后匹配,在匹配失败时关注的是文本串中参加匹配的最末位字符的下一位字符。如果该字符没有在匹配串中出现则直接跳过,即移动步长= 匹配串长度+ 1;否则,同BM算法一样其移动步长=匹配串中最右端的该字符到末尾的距离+1。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int getIndex(char *tp, char ch) {
if (tp == NULL || !ch)
return -1;
int tp_len = strlen(tp);
for (int i = 0; i < tp_len; i++) {
if (ch == tp[i]) {