Skip to content

Instantly share code, notes, and snippets.

View luoyjx's full-sized avatar
📖

yanjixiong luoyjx

📖
View GitHub Profile
import {
createParser,
ParsedEvent,
ReconnectInterval,
} from "eventsource-parser";
export interface OpenAIStreamPayload {
model: string;
prompt: string;
temperature: number;
@luoyjx
luoyjx / memory_limit_in_container.go
Created December 8, 2022 06:51
how to get memory limit in golang server without k8s client
// Open the cgroup hierarchy of the current container
f, err := os.Open("/sys/fs/cgroup/memory/memory.limit_in_bytes")
if err != nil {
// Handle error
}
defer f.Close()
// Read the maximum memory limit from the file
var maxMemLimit int64
_, err = fmt.Fscanf(f, "%d", &maxMemLimit)
@luoyjx
luoyjx / docker-compose.yml
Created August 1, 2022 14:44
kafka docker compose yaml
version: "3"
services:
kafka:
image: wurstmeister/kafka:2.11-0.11.0.3
restart: on-failure:3
links:
- zookeeper
ports:
- "9092:9092"
- "9093:9093"
@luoyjx
luoyjx / golang_pipe_http_response.go
Created September 27, 2020 07:16 — forked from ifels/golang_pipe_http_response.go
golang pipe the http response
package main
import (
"io"
"net/http"
"os/exec"
)
var (
BUF_LEN = 1024
@luoyjx
luoyjx / array-diff.html
Created June 23, 2020 08:38 — forked from Munawwar/array-diff.html
O(n) array diff & patch algorithm in JavaScript (unlike LCS, this is a trade-off for speed than minimum changes).
<html>
<body>
<script>
/**
* This array diff algorithm is useful when one wants to detect small changes
* (like consecutive insertions or consecutive deletions) several times
* in short time intervals. Alternative algorithms like LCS woud be too expensive
* when running it too many times.
*/
-- 操作的Redis Key
local rate_limit_key = KEYS[1]
-- 每秒最大的QPS许可数
local max_permits = ARGV[1]
-- 此次申请的许可数
local incr_by_count_str = ARGV[2]
-- 当前已用的许可数
local currentStr = redis.call('get', rate_limit_key)
local current = 0
if currentStr then
@luoyjx
luoyjx / code.js
Created September 29, 2019 03:16
create array fast way
let f = length => Array.from({length}).map((v,k) => k);
@luoyjx
luoyjx / codeEditor.js
Created September 28, 2019 02:17
CodeEditor
import React from 'react';
import faTrashAlt from '@fortawesome/fontawesome-free-solid/faTrashAlt';
import faUser from '@fortawesome/fontawesome-free-solid/faUser';
import { classes, extension } from 'common/util';
import { actions } from 'reducers';
import { connect } from 'react-redux';
import { languages } from 'common/config';
import { Button, Ellipsis, FoldableAceEditor } from 'components';
import styles from './CodeEditor.module.scss';
@luoyjx
luoyjx / update-golang.md
Created July 9, 2019 04:59 — forked from nikhita/update-golang.md
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

@luoyjx
luoyjx / upload.js
Created June 18, 2019 08:25
upload file with node-fetch & form-data
const fetch = require('node-fetch')
const FormData = require('form-data')
const pdfPath = '/path/to/pdfFile'
async function upload () {
const formData = new FormData()
formData.append('name', 'xxx')
formData.append('filename', 'xxxxxxxx.pdf')
formData.append('file', fs.readFileSync(pdfPath), {