Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
from slackclient import SlackClient
from elasticsearch import Elasticsearch
from plugins.elastic.elastic import CHANNEL, USER_ID, process_message, to_metric
from datetime import datetime
import yaml
import json
ELASTIC_HOST = '[your-hostname]'
SIZE = 1000
"""
Listens to incoming Slack messages from cardbucks-bot and stores the metrics in Elasticsearch
"""
from elasticsearch import Elasticsearch
from datetime import datetime
import re
# rtmbot variables
crontable = []
outputs = []

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.

# This exists so the user can create a short URL for private repos
# API requires Accept header to download a file. We use the API to pass netrc auth via `curl -n`.
curl -ns https://api.github.com/repos/confluentinc/cli/contents/install-ccloud.sh?ref=master -H Accept:application/vnd.github.raw | bash -s -- $@
project_name: confluent-cli
builds:
-
binary: confluent
main: .
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}}
gcflags:
- -trimpath={{.Env.GOPATH}}

Keybase proof

I hereby claim:

  • I am codyaray on github.
  • I am codyaray (https://keybase.io/codyaray) on keybase.
  • I have a public key ASDdfGgq-l4vGUXrNit4v_LU-9b65yhAKF3479ySLSgcvwo

To claim this, I am signing this object:

@codyaray
codyaray / invite_to_slack.js
Last active December 15, 2017 20:57 — forked from dommmel/invite_to_slack.js
Zapier Code to auto invite users to slack
var slackTeam = "YOUR_SLACK_TEAM_NAME ";
var token = 'YOUR_ADMIN_TEST_TOKEN';
var channels = 'C1234567890,G12345678';
// A test token will suffice.
// You can generate one at https://api.slack.com/docs/oauth-test-tokens
// Just make sure that the user issuing the test token is an admin.
var url = 'https://'+ slackTeam + '.slack.com/api/users.admin.invite';
fetch(url, {
@codyaray
codyaray / alert-mappings.json
Created March 1, 2017 19:10
straight from _mappings with updated @timestamp formats (used to be long)
{
"test": {
"properties": {
"index": {
"type": "string"
},
"host": {
"type": "string"
},
"alert_level_name": {
{
"status": "failed",
"start_timestamp": "2017-01-30T18:05:01.614373Z",
"log": [
{
"status": "requested",
"timestamp": "2017-01-30T18:05:01.639000Z"
},
{
"status": "scheduled",
from myhandlers import EnhancedRotatingFileHandler
import time
import logging
def demo():
log_filename = 'log_rotate.log'
logger = logging.getLogger('MyLogger')
logger.setLevel(logging.DEBUG)
handler = EnhancedRotatingFileHandler(
log_filename, maxBytes=10,