Skip to content

Instantly share code, notes, and snippets.

View seanmccann's full-sized avatar
🏋️

Sean McCann seanmccann

🏋️
View GitHub Profile
# Lo-fi client for the Facebook API. E.g.:
#
# fb = FacebookClient.new(:api_key => 'api-key', :secret => 'secret')
# fb.call 'users.getInfo', :session_key => 'session-key', :uids => 'user-id', :fields => 'birthday'
#
# by Scott Raymond <[email protected]>
# Public Domain.
#
class FacebookClient
def initialize(default_params={})
server {
listen 80;
server_name stu.mp;
# if the request uri was a directory, store the index page name
if ($request_uri ~ /$) {
set $store_extra index.html;
}
# proxy module defaults
//
// EVPCConversationViewController.h
// EVPcard
//
// Created by Sebastien Arbogast on 27/02/14.
// Copyright (c) 2014 Epseelon. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <JSMessagesViewController/JSMessagesViewController.h>
@seanmccann
seanmccann / Flex.js
Created August 17, 2017 20:40 — forked from jorilallo/Flex.js
Flexbox component for React
// @flow
import React from 'react';
import styled from 'styled-components';
type GlobalCssValues = 'initial' | 'inherit' | 'unset';
type WrapValue = 'nowrap' | 'wrap' | 'wrap-reverse' | GlobalCssValues;
type JustifyValue =
| 'center'
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@seanmccann
seanmccann / setup.sh
Created January 7, 2021 16:39 — forked from shaneog/setup.sh
GCE install for Buildkite Agent v3 (Beta)
#!/usr/bin/env bash
set -eo pipefail
DATE=$(date +%Y%m%d-%H%M%S)
GROUP_NAME="buildkite-agent"
TEMPLATE_NAME="${GROUP_NAME}-${DATE}"
# Builder Group
gcloud compute instance-templates create "${TEMPLATE_NAME}-builder" \

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.

import React, { Fragment } from 'react';
import Document, { Head, Main, NextScript } from 'next/document';
import { GA_TRACKING_ID } from '../core/gtag';
type Props = {
isProduction: boolean,
}
export default class extends Document<Props> {
static async getInitialProps(ctx) {
@seanmccann
seanmccann / f1000.csv
Created November 3, 2023 22:53 — forked from hrbrmstr/f1000.csv
2015 Fortune 1000 List with industry & website
name industry sector website rank
Walmart General Merchandisers Retailing http://www.walmart.com 1
Exxon Mobil Petroleum Refining Energy http://www.exxonmobil.com 2
Chevron Petroleum Refining Energy http://www.chevron.com 3
Berkshire Hathaway Insurance: Property and Casualty (Stock) Financials http://www.berkshirehathaway.com 4
Apple Computers, Office Equipment Technology http://www.apple.com 5
General Motors Motor Vehicles and Parts Motor Vehicles & Parts http://www.gm.com 6
Phillips 66 Petroleum Refining Energy http://www.phillips66.com 7
General Electric Diversified Financials Financials http://www.ge.com 8
Ford Motor Motor Vehicles and Parts Motor Vehicles & Parts http://www.ford.com 9