Skip to content

Instantly share code, notes, and snippets.

View cgiosy's full-sized avatar

cgiosy cgiosy

View GitHub Profile
@cgiosy
cgiosy / sort_by_angle.cpp
Last active May 3, 2024 09:45
각도로 정렬하기
auto m=partition(A.begin(), A.end(), [&](pii p) { return p<pii{}; });
sort(A.begin(), m, [&](pii a, pii b) { return cross(a, b)<0; });
sort(m, A.end(), [&](pii a, pii b) { return cross(a, b)<0; });
@cgiosy
cgiosy / bitset.cpp
Last active March 26, 2025 04:35
std::bitset addition & subtraction
#define private public
#include <bitset>
#undef private
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
template<size_t _Nw> void _M_do_sub(_Base_bitset<_Nw> &A, const _Base_bitset<_Nw> &B) {
for(int i=0, c=0; i<_Nw; i++)
@cgiosy
cgiosy / decycle.js
Last active August 13, 2021 00:26
JSON decycle
const replaceSetMap = (object) => {
if (object) {
if (object.constructor === Set) return [...object];
if (object.constructor === Map) return Object.fromEntries(object);
}
return object;
};
const decycle = (rootObject, { replacer = replaceSetMap, seen = new WeakMap() } = {}) => {
const _decycle = (object, path = "$") => {
@cgiosy
cgiosy / cheat.js
Last active November 24, 2021 14:32
const replaceSetMap = (object) => {
if (object) {
if (object.constructor === Set) return [...object];
if (object.constructor === Map) return Object.fromEntries(object);
}
return object;
};
const firstScan = ($, needle, { replacer = replaceSetMap, seen = new WeakMap() } = {}) => {
const found = [];
@cgiosy
cgiosy / kd_tree.cpp
Last active September 12, 2021 22:30
K-D Tree
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
struct point {
int x, y;
point operator-(point v) const { return { x - v.x, y - v.y }; }
ll operator~() const { return ll(x) * x + ll(y) * y; }
};
// #define DONT_USE_SIMD
// #pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <iostream>
#include <x86intrin.h>
#define INDEX_BIT_SIZE 14
using i16 = short;
using i32 = int;
using u32 = unsigned int;
@cgiosy
cgiosy / concurrent.js
Last active June 1, 2022 03:18
Asynchronous Function Concurrent Executor
const concurrent = async(limit, fns) => {
const result = [];
const runningTasks = [];
for (const fn of fns) {
const promise = fn();
result.push(promise);
const emptyIndex = runningTasks.length === limit ? await Promise.race(runningTasks) : runningTasks.length;
const currentIndex = emptyIndex;
runningTasks[emptyIndex] = promise.then(() => currentIndex);
}
@cgiosy
cgiosy / HTTP Proxy Server Benchmarks.md
Last active February 21, 2022 16:13
HTTP Proxy Server Benchmarks

HTTP Proxy Server Benchmarks

h2load를 사용해 리버스 프록시 서버로서의 H2ONginx를 벤치마크 및 비교해 보았다. HTTP/2와 HTTP/3 각각에 대해 테스트하였고, 벤치마크 명령어를 다섯 번 실행하여 시간이 가장 적게 소모된 경우를 뽑았다.

Configurations

H2O

2022년 1월 8일 기준 최신 커밋을 빌드하였으며, ECDH Curves 관련 PR을 적용했다.

@cgiosy
cgiosy / build.cpp
Last active February 23, 2022 15:39
Simple Treap
function<void(shared_ptr<node>&&)> dfs=[&](shared_ptr<node>&& p) {
if(p->l) p->push(p->l), dfs(move(p->l));
A[M++]=p->x;
if(p->r) p->push(p->r), dfs(move(p->r));
};
function<shared_ptr<node>(int, int)> build=[&](int l, int r) {
int m=(l+r)>>1;
auto p=node::New(A[m]);
if(l<m) p->l=build(l, m-1);
@cgiosy
cgiosy / gen.js
Last active March 14, 2023 18:09
const fs = require('fs');
const filenum = 30; // or 100
const lines = 2000000; // or 1000000
const errors = 100000;
const ratio = lines / errors | 0;
const count = lines / ratio | 0;
for (let i = 1; i <= filenum; i += 1) {