Skip to content

Instantly share code, notes, and snippets.

View benclmnt's full-sized avatar
🎯
Focusing

Bennett Clement benclmnt

🎯
Focusing
View GitHub Profile
@benclmnt
benclmnt / ec2map.js
Last active March 20, 2024 05:32
Get EC2 name to instance_id mapping from AWS console
// start from the last page and update the # of pages below
let pages = 100;
let s = `name,instance_id,instance_type\n`;
for (let i = 0; i < pages; i++) {
document.querySelectorAll('tr[data-selection-item="item"]').forEach(x => {
let name = x.querySelectorAll('td')[1].textContent;
let instanceID = x.querySelectorAll('td')[2].textContent;
let instanceType = x.querySelectorAll('td')[4].textContent;
s += `${name},${instanceID},${instanceType}\n`
});

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.

@benclmnt
benclmnt / advice.md
Last active January 16, 2025 08:16
NUS CS Planning

Module Planning

Here be some of my notes on how to plan your CS career (specifically NUS).

First things first, I encourage you to have your own module plan (say, in a Google Sheets). You can start with the suggested module plan, but they are quite generic and might not suit your personal goals (e.g. some advanced modules you'd like to take have prerequisites that are offered in odd semesters only).

Having your own module plan will also make you easier to include other non-academic activities too.

General advice

  • Take as many foundational (core) modules while you can. You never want to be left behind due to missing prerequisites.
@benclmnt
benclmnt / App.js
Last active July 2, 2020 03:16
Manual Cognito setup without using amplify-cli (User Pool with social idp)
import React from 'react';
import {
BrowserRouter as Router,
Route,
Switch,
Redirect,
} from 'react-router-dom';
import Amplify, { Auth, Hub } from 'aws-amplify';
import { AmplifySignInButton } from '@aws-amplify/ui-react';
import amplifyConfig from './amplify-config.js';