The official installation guide (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description.
- Image from https://www.archlinux.org/
#![cfg(target_os = "macos")] | |
use rustix::event::kqueue; | |
use std::io::{Read, Write}; | |
use std::net::{TcpListener, TcpStream}; | |
use std::os::fd::AsRawFd; | |
use std::time::Duration; | |
fn main() { | |
// kickoff a simple echo server we can hit for demo purposes |
#[derive(Debug, PartialEq)] | |
enum State { | |
Waiting { waiting_time: usize }, | |
Filling { rate: usize }, | |
Done, | |
Failure(String), | |
} | |
#[derive(Debug, Clone, Copy)] | |
enum Event { |
use std::fmt; | |
use log::kv::{self, Source, value::{self, Fill}}; | |
use tracing::{Value, Field, field::{self, Visit}}; | |
#[doc(hidden)] | |
pub struct LogField<'kvs>(&'kvs Field, &'kvs dyn Value); | |
impl fmt::Debug for LogField<'_> { |
Roots for record 0 (stored at leaf 0): [ 0 ] | |
0: 0 | |
Roots for record 1 (stored at leaf 2): [ 1 ] | |
0: 0─┐ | |
1 | |
1: 2─┘ | |
Roots for record 2 (stored at leaf 4): [ 1, 4 ] | |
0: 0─┐ |
The official installation guide (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description.
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'octokit' | |
options = {} | |
OptionParser.new do |opt| | |
opt.on('-s', '--secret SECRET', 'GitHub access token') { |o| options[:secret] = o } | |
opt.on('-r', '--repo-slug REPO_SLUG', 'Repo slug. i.e.: apple/swift') { |o| options[:repo_slug] = o } | |
opt.on('-c', '--changelog-file CHANGELOG_FILE', 'Changelog path') { |o| options[:changelog_file] = o } |
npm config set loglevel http | |
npm config set progress false | |
npm config set package-lock false | |
npm config set save false | |
mkdir -p ~/.config/configstore/ | |
printf '{"optOut": true,"lastUpdateCheck": 0}' > ~/.config/configstore/update-notifier-npm.json |
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.
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.