Skip to content

Instantly share code, notes, and snippets.

View senthil1216's full-sized avatar

senthil sivasubramanian senthil1216

View GitHub Profile

Rate limiting with Redis

June 2011 - Chris O'Hara - (archived original post)

Rate limiting can be an effective way of conserving resources and preventing automated or nefarious activities on your site.

A common use case is to limit the amount of requests an IP can make over a certain time frame. For example, you might want to restrict users from using an expensive search utility on your site. If the user attempts to search more than 5 times a minute, you can redirect them to another page informing them that they need to wait.

IP based rate limiting is already in use on larger sites. Google and Yahoo both employ the technique to prevent (or at least complicate) automated requests to their services.

Advanced Dynamic Programming
For Reading
Commonly Used DP state domains : http://apps.topcoder.com/forums/?module=Thread&threadID=697369&start=0
General Aspects of DP : http://apps.topcoder.com/forums/?module=Thread&threadID=700080&start=0
Optimizing DP solutions : http://apps.topcoder.com/forums/?module=Thread&threadID=697925&start=0
@senthil1216
senthil1216 / ConsumerExampleDemo.java
Created September 29, 2019 07:09
Consumer Example Java
public class ConsumerExampleDemo {
Employees employees;
Consumer consumer;
public ConsumerExampleDemo(Consumer consumer) {
employees = new Employees();
// employees = prepareEmployees(employees); // Look at the implementation for this method in the above Non-Consumer way
this.consumer = consumer;
}
@senthil1216
senthil1216 / NonConsumerExampleDemo.java
Created September 29, 2019 06:52
Non Consumer Example
public class NonConsumerExampleDemo {
/****** BEGIN ******/
/** Setup code to prepare the list of employees **/
private Employee createEmployee(int id, double salary, String firstName, String lastName, int age) {
Employee emp = new Employee();
emp.EmployeeId = id;
emp.Salary = salary;
emp.FirstName = firstName;
emp.LastName = lastName;
@senthil1216
senthil1216 / NodeDereference.java
Created May 12, 2018 07:07
uber-TPS question
import java.util.*;
public class Question {
class Node {
// A unique ID of a node
int id;
// Arbitrary value
String name;
// A list of child node IDs
ArrayList<Integer> references;
You are given a NxN matrix composed of lowercase letters and a list of words. Your task is to find out the largest list of words that can be formed by the letters in the matrix.
Constraints:
each letter can only be used once for a word;
once the cell (letter) in the matrix is taken by a word, then the other words in the same list cannot use that cell again.
Example:
Input:
{
{‘o’, ‘a’, ‘a’, ‘n’},
import java.util.*;
public class AlienLanguage {
class Graph{
private Map<Character, LinkedHashSet<Character>> adj;
public Graph(){
adj = new HashMap<Character, LinkedHashSet<Character>>();
}
public void addEdge(Character st, Character dest){
LinkedHashSet<Character> chars = new LinkedHashSet<>();
@senthil1216
senthil1216 / Flatten2DVector.java
Created March 5, 2018 02:19
Flatten 2D vector
import java.util.*;
/*
https://leetcode.com/problems/flatten-2d-vector/description/
Implement an iterator to flatten a 2d vector.
For example,
Given 2d vector =
[
[1,2],
@senthil1216
senthil1216 / LongestAbsoluteFilePath.java
Created March 1, 2018 07:38
Longest Absolute file path
// https://leetcode.com/problems/longest-absolute-file-path/description/
class Solution {
class FileLevel {
int level; int len;
}
public int countOfCharacter(String s, Character seq){
int count = 0;
for(int i = 0 ;i < s.length();i++){
@senthil1216
senthil1216 / pub_sub.js
Last active March 18, 2022 10:04
Pub Sub in javascript
class EventEmitters {
constructor(){
this.listeners = new Map();
this.addListeners = this.addListeners.bind(this);
this.emit = this.emit.bind(this);
}
addListeners(label, callBack){
let callBacks = [];
if(this.listeners.has(label)){
callBacks = this.listeners.get(label);