Skip to content

Instantly share code, notes, and snippets.

@FilipBartos
FilipBartos / axios-response-interceptor.js
Last active April 11, 2024 07:03
Axios response interceptor for access token refresh supporting 1 to N async requests
let isAlreadyFetchingAccessToken = false
let subscribers = []
function onAccessTokenFetched(access_token) {
subscribers = subscribers.filter(callback => callback(access_token))
}
function addSubscriber(callback) {
subscribers.push(callback)
}
@jpalala
jpalala / nginx-php-fpm-mysql-and-phpmyadmin-on-mavericks.md
Last active September 9, 2022 14:52
How to get nginx php-fpm on your mac machine

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.

Thanks for taking the time to take our Fullscreen code challenge!

Please post your answers to a JSBin within a week of receiving this test. Feel free to use whichever compiled-to-JS language you want (Coffeescript, ES6/Babel, vanilla Javascript, etc..), but be prepared to explain what your code compiles down to in plain ol' Javascript if you do.

Getting classy.

  • Create a Vehicle class with getName and setName methods which manipulate a name property on its class instances.
  • Write a getter/setter for wheels and seats using the get/set keywords if your language of choice supports them (pro-tip: it probably does).
  • Create Car and Motorcycle classes which extend from Vehicle and set the number of seats/wheels appropriately.
  • Instances should be properly inherit from your class, so myCarInstance instanceof Car should return true.
@itsmikeq
itsmikeq / rdd.md
Created October 29, 2015 01:48 — forked from kenchung/rdd.md
Resume Driven Development Challenge

Resume Driven Development Challenge

Using the Github Archive API, create a command-line tool to find popular repos to add lots of hipster acronyms to your resume!

It should support a date range in the past in case time travel becomes possible and you decide to go back and learn different things.

You should use Ruby or Javascript based on the role you are being considered for.

Given the date range, you'll collect event data from the Github Archive and give each repo a popularity score.

@dodyg
dodyg / gist:5823184
Last active October 20, 2024 12:25
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

@alex-zige
alex-zige / gist:5795358
Last active June 8, 2023 07:49
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views