Skip to content

Instantly share code, notes, and snippets.

View Octobug's full-sized avatar
😇
Busy as hell

Linc Lin Octobug

😇
Busy as hell
View GitHub Profile
@MarshalW
MarshalW / koa-swagger-jsdoc.md
Created May 23, 2021 12:13
koa swagger with jsdoc

koa swagger with jsdoc

需要的包:

npm i koa2-swagger-ui swagger-jsdoc

app/index.js

@SleepWalker
SleepWalker / README.md
Last active May 28, 2024 01:35
swagger-jsdoc with koa2-swagger-ui middleware example

This is an example how to setup swagger docs api endpoint for your koa app.

Usage

const Koa = require('koa');
const path = require('path');
const http = require('http');

const swagger = require('./swagger');

Libuv and libev, two I/O libraries with similar names, recently had the privilege to use both libraries to write something. Now let's talk about my own subjective expression of common and different points.

The topic of high-performance network programming has been discussed. Asynchronous, asynchronous, or asynchronous. Whether it is epoll or kqueue, it is always indispensable to the asynchronous topic.

Libuv is asynchronous, and libev is synchronous multiplexing IO multiplexing.

Libev is a simple encapsulation of system I/O reuse. Basically, it solves the problem of different APIs between epoll and kqueuq. Ensure that programs written using livev's API can run on most *nix platforms. However, the disadvantages of libev are also obvious. Because it basically just encapsulates the Event Library, it is inconvenient to use. For example, accept(3) requires manual setnonblocking after connection. EAGAIN, EWOULDBLOCK, and EINTER need to be detected when reading from a socket. This is a

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@rymawby
rymawby / stripe-credit-card-numbers.md
Last active October 18, 2024 16:25
Stripe test credit card numbers for use in development

#Test credit card numbers to use when developing with Stripe

4242424242424242 Visa

4012888888881881 Visa

4000056655665556 Visa (debit)

@staltz
staltz / introrx.md
Last active November 19, 2024 13:42
The introduction to Reactive Programming you've been missing
@jboner
jboner / latency.txt
Last active November 19, 2024 11:10
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD