Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yoshuawuyts's full-sized avatar

Yosh yoshuawuyts

View GitHub Profile
@rust-play
rust-play / playground.rs
Created September 16, 2019 02:59
Code shared from the Rust Playground
#[derive(Debug, PartialEq)]
enum State {
Waiting { waiting_time: usize },
Filling { rate: usize },
Done,
Failure(String),
}
#[derive(Debug, Clone, Copy)]
enum Event {
@KodrAus
KodrAus / tracing_log.rs
Last active June 29, 2020 19:11
Converting between `tracing` key values and `log` key values
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─┐
@jamesmunns
jamesmunns / arch-linux-install.md
Created July 28, 2018 16:04 — forked from kylemanna/arch-linux-install.md
Minimal instructions for installing arch linux on an UEFI NVMe system with full system encryption using dm-crypt and luks
@valeriomazzeo
valeriomazzeo / github_release.rb
Created July 5, 2017 21:24
Creates or update a GitHub release for the given tag name
#!/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 }
@mafintosh
mafintosh / npm-classic-config.sh
Last active June 21, 2018 17:40
Resets the npm defaults to how they used to be
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

⚠️ this is now stupidly out of date

Computers

  • 13" Macbook Pro 3.3 GHz i7 (late 2016)
  • Microsoft Surface Book (2016)

Peripherals

@sethvincent
sethvincent / README.md
Last active April 8, 2017 17:39
useful DOM element modules

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.

@sfan5
sfan5 / alpine-container.sh
Last active April 8, 2024 17:44
bootable systemd-nspawn containers with Linux distributions: Alpine, Arch Linux, Ubuntu
#!/bin/bash -e
# Creates a systemd-nspawn container with Alpine
MIRROR=http://dl-cdn.alpinelinux.org/alpine
VERSION=${VERSION:-v3.19}
APKTOOLS_VERSION=2.14.3-r1
wget_or_curl () {
if command -v wget >/dev/null; then