Skip to content

Instantly share code, notes, and snippets.

btrfs fi show -d
Label: '2019.02.19-20:17:48 v23824' uuid: 7c19084c-9c53-4cea-b287-0e1a43e6860b
Total devices 1 FS bytes used 13.95TiB
devid 1 size 29.07TiB used 23.18TiB path /dev/md2
syno_poweroff_task -d
(Interrupt this after a while to prevent losing SSH completely)
@dldinternet
dldinternet / ssm_parameter_store.py
Created March 20, 2021 05:00 — forked from nqbao/ssm_parameter_store.py
Python class to provide a dictionary-like interface to access AWS SSM Parameter Store easily
# Copyright (c) 2018 Bao Nguyen <b@nqbao.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@dldinternet
dldinternet / notify_smtp.py
Created May 18, 2020 16:16 — forked from jamescalam/notify_smtp.py
Function used to send a MIMEMultipart email object (msg) to your own email using Python's smtplib library.
import smtplib
import socket
def send(server='smtp-mail.outlook.com', port='587', msg):
# contain following in try-except in case of momentary network errors
try:
# initialise connection to email server, the default is Outlook
smtp = smtplib.SMTP(server, port)
# this is the 'Extended Hello' command, essentially greeting our SMTP or ESMTP server
smtp.ehlo()
@dldinternet
dldinternet / notify_message.py
Created May 18, 2020 16:15 — forked from jamescalam/notify_message.py
Example of using Python's email module to build an email message object containing a subject, body, attachments, and images.
import os
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
def message(subject="Python Notification", text="", img=None, attachment=None):
# build message contents
msg = MIMEMultipart()
msg['Subject'] = subject # add in the subject

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.

@dldinternet
dldinternet / example.rb
Created June 13, 2017 18:49 — forked from Nakilon/example.rb
Simplified example of using google-cloud-monitoring to store custom metrics of my daemons RAM/fd leakage
require "google/cloud/monitoring/v3/metric_service_client"
client = Google::Cloud::Monitoring::V3::MetricServiceClient.new
project_path = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path JSON.load(File.read ENV["GOOGLE_APPLICATION_CREDENTIALS"])["project_id"]
create_custom_gauge_metric = lambda do |type, display_name, value_type, labels = {}|
metric_descriptor = Google::Api::MetricDescriptor.new( # googleapis-common-protos-1.3.5/lib/google/api/metric_pb.rb
type: "custom.googleapis.com/#{type}",
metric_kind: :GAUGE, # google-cloud-monitoring-0.24.0/lib/google/cloud/monitoring/v3/doc/google/api/metric.rb
value_type: value_type, # google-cloud-monitoring-0.24.0/lib/google/cloud/monitoring/v3/doc/google/api/metric.rb
display_name: display_name,
# vim: ft=sh:ts=4:sw=4:autoindent:expandtab:
# Author: Avishai Ish-Shalom <avishai@fewbytes.com>
# We need to specify GNU sed for OS X, BSDs, etc.
if [[ "$(uname -s)" == "Darwin" ]]; then
SED=gsed
else
SED=sed
fi

New Ruby software project procedure

First, ensure the following tools are available on the local system and reasonably up to date:

  • Git
  • Git-flow
  • RVM
  • Bash
  • SSH