I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!
\
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: Domenico Monaco, Yong Mook Kim | |
* | |
* Source: https://gist.github.com/kiuz/816e24aa787c2d102dd0 | |
* | |
* License: GNU v2 2014 | |
* | |
* Fork / Learned: http://www.mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/ | |
* | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author rchytas | |
* | |
* Use any way you like :) | |
* | |
*/ | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileWriter; |
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.
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner.class) | |
@TestPropertySource("classpath:server-test.properties") | |
public class SpelUnitTest { | |
public static final Logger logger = LoggerFactory.getLogger(Sample.class); | |
@Value("${testclock.start}") | |
private String startTime; | |
@Autowired |