Skip to content

Instantly share code, notes, and snippets.

View 42milez's full-sized avatar
🍵

Akihiro TAKASE 42milez

🍵
View GitHub Profile
@maiha
maiha / RateLimit.md
Last active May 23, 2024 13:10
RateLimitアルゴリズムまとめまとめ (→ Sliding window countersでOK)

TL;DR

  • Leaky bucket : キューイングして出力量(consume)で調節 (アルゴリズムというかキューを使って調節)
  • Token bucket : 定期的に資源を追加し平均値を調節。バーストに強い (ソシャゲのスタミナ回復)
  • Fixed window counters : 単位時間あたりの上限値を指定。キューを使わないLeaky bucket。境界の2倍問題あり
  • Sliding window log : 総数(counters)でなくアクセス時刻(log)で管理。境界問題を解消する一方、消費増加がぱない(IntArray(Time))
  • Sliding window counters : countersのままで、単位時間の割合計算によって境界問題を解消。これにしておけば間違いない

参考: 様々なrate limitアルゴリズム

@mbinna
mbinna / effective_modern_cmake.md
Last active June 26, 2024 13:26
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@josephg
josephg / main.c
Created August 26, 2017 08:20
kqueue network & file example
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/event.h>
#include <netdb.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
@wxdao
wxdao / open_utun.c
Last active April 13, 2024 18:39 — forked from bringhurst/gist:1693075
How to open utun device in OS X
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/kern_control.h>
#include <net/if_utun.h>
#include <sys/ioctl.h>
#include <sys/kern_event.h>
int open_utun(int num) {
int err;
@joepie91
joepie91 / random.md
Last active June 24, 2024 09:17
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@dreikanter
dreikanter / encrypt_openssl.md
Last active June 20, 2024 10:15 — forked from crazybyte/encrypt_openssl.txt
File encryption using OpenSSL

Symmetic encryption

For symmetic encryption, you can use the following:

To encrypt:

openssl aes-256-cbc -salt -a -e -in plaintext.txt -out encrypted.txt

To decrypt:

@mono0926
mono0926 / commit_message_example.md
Last active June 24, 2024 02:44
[転載] gitにおけるコミットログ/メッセージ例文集100
@RafaelMCarvalho
RafaelMCarvalho / ransackable_scopes.rb
Created May 24, 2016 15:21 — forked from gabeodess/ransackable_scopes.rb
Ransack with JSONB query for array values (or condition)
class Edition < ActiveRecord::Base
scope :distances_any, -> (*distances) {
where("distances ?| array[:values]", values: distances)
}
private
def self.ransackable_scopes(auth_object = nil)
%i(distances_any)
end
@kotakanbe
kotakanbe / mohikan_slack_channels.md
Last active October 14, 2023 19:26
モヒカンslack( https://mohikan.slack.com )のチャネルリスト
@gubatron
gubatron / dht-walkthrough.md
Last active June 24, 2024 01:05
DHT walkthrough notes

DHT Walkthrough Notes

I've put together these notes as I read about DHT's in depth and then learned how the libtorrent implementation based on the Kademlia paper actually works.

What problem does this solve?

400,000,000,000 (400 billion stars), that's a 4 followed by 11 zeros. The number of atoms in the universe is estimated to be around 10^82. A DHT with keys of 160 bits, can have 2^160 possible numbers, which is around 10^48