Skip to content

Instantly share code, notes, and snippets.

View AyoAlfonso's full-sized avatar
:octocat:
Building

Ayo Alfonso AyoAlfonso

:octocat:
Building
View GitHub Profile
@jasongaylord
jasongaylord / beacon.html
Created August 27, 2020 18:36
Beacon CSS - An example using CSS animations to create a beacon for use on something like a map or to call attention visually.
<!DOCTYPE HTML>
<html lang="en">
<head>
<style>
.dot {
background-color: red;
border-radius: 50%;
width: 20px;
height: 20px;
display: block;
/**
Using input object type for mutations
**/
type Mutation {
register(input : createPersonInput!):RegisterUserResponse!
}
input createPersonInput{
name: String!
@AyoAlfonso
AyoAlfonso / sample.js
Created November 12, 2018 09:33 — forked from chowryan/sample.js
react setstate?
// Method 1:
class Parent extends Component {
state = { foo: '', bar: '', buzz: '' }
render() {
return (
<Child
setParentState={this.setState}
>
)
@ibraheem4
ibraheem4 / postgres-brew.md
Last active April 19, 2025 14:27 — forked from sgnl/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@binario200
binario200 / CheckboxWithLabel.js
Last active April 14, 2022 08:48
How to test react components with Jest
import React from 'react';
export default class CheckboxWithLabel extends React.Component {
constructor(props) {
super(props);
this.state = {isChecked: false};
// bind manually because React class components don't auto-bind
// http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
this.onChange = this.onChange.bind(this);
@mpj
mpj / example01.js
Created August 14, 2017 07:38
Code for the async/await episode of Fun Fun Function.
const response = await fetch(`https://catappapi.herokuapp.com/users/${userId}`)
const data = await response.json()
return data.imageUrl
}
@scwood
scwood / attemptWithRetry.js
Last active October 4, 2018 05:42
Exponential backoff retry logic for a function that returns a Promise
/**
* Retries a function that returns a promise a given number of times and backs
* off each attempt exponentially.
*
* @param {Function} promiseGenerator The function to retry.
* @param {number} [attempts=5] Number of attempts to make.
* @param {number} [delay=1000] Initial delay between attempts in ms.
* @return {Promise}
*/
function attemptWithRetry(promiseGenerator, attempts = 5, delay = 100) {

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.

Unit testing react with Jest


What is a unit test?

  • When given some input, does the output look like x?
  • Runs quickly
@thegitfather
thegitfather / vanilla-js-cheatsheet.md
Last active April 28, 2025 16:22
Vanilla JavaScript Quick Reference / Cheatsheet