Skip to content

Instantly share code, notes, and snippets.

View exceptionplayer's full-sized avatar
🦊
come on!

Danny W. exceptionplayer

🦊
come on!
  • HongKong
  • 20:24 (UTC +08:00)
View GitHub Profile
@exceptionplayer
exceptionplayer / 0_reuse_code.js
Created April 16, 2016 06:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@exceptionplayer
exceptionplayer / HelloCovariance.java
Created June 8, 2016 08:13 — forked from AlainODea/HelloCovariance.java
Exception in thread "main" java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class HelloConvariance {
public static void main(String[] args) {
ConcurrentHashMap<String, String> properties = new ConcurrentHashMap<>();
Set<String> keySet = properties.keySet();
}
}
@exceptionplayer
exceptionplayer / gist:7b8c4f0a010eaa4a7183c3181ba8d621
Created October 14, 2016 06:55 — forked from danielestevez/gist:2044589
GIT Commit to an existing Tag
1) Create a branch with the tag
git branch {tagname}-branch {tagname}
git checkout {tagname}-branch
2) Include the fix manually if it's just a change ....
git add .
git ci -m "Fix included"
or cherry-pick the commit, whatever is easier
git cherry-pick {num_commit}
@exceptionplayer
exceptionplayer / gist:e3481c7335a30e95491ed92bcdd5e000
Created April 6, 2017 02:25 — forked from jcarlosgarcia/gist:1621770
Set system properties via Spring XML configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean id="systemProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" value="#{@systemProperties}" />
<property name="targetMethod" value="putAll" />
@exceptionplayer
exceptionplayer / sync-gitlab-projects
Last active March 24, 2023 02:42 — forked from JonasGroeger/sync-projects
Gitlab: Clone / Pull all projects in a group in gitlab(批量下载gitlab中的项目)
#!/usr/bin/env bash
# should install jq first, for mac:brew install jq
# Documentation
# https://docs.gitlab.com/ce/api/projects.html#list-projects
NAMESPACE="your group name in gitlab"
BASE_PATH="https://gitlab.example.com/"
PROJECT_SEARCH_PARAM=""
@exceptionplayer
exceptionplayer / pom.xml
Created November 2, 2017 10:11 — forked from tomsoete/pom.xml
Spring Best Practices Maven Pom
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gordondickens.sample</groupId>
<artifactId>sample-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
@exceptionplayer
exceptionplayer / linux_smap_analyzer.py
Created January 4, 2018 10:57 — forked from LanderlYoung/linux_smap_analyzer.py
Linux /proc/<pid>/smaps analyzer python script
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
'''
analyze /proc/<pid>/smaps
doc
http://liutaihua.github.io/2013/04/25/process-smaps-analysis.html
@exceptionplayer
exceptionplayer / git-branch.md
Created March 14, 2018 03:54 — forked from yisibl/git-branch.md
在Mac、Linux 终端显示 Git 当前所在分支

在Mac、Linux 终端显示 Git 当前所在分支

  1. 进入你的home目录
cd ~
  1. 编辑.bashrc文件
@exceptionplayer
exceptionplayer / TokenGenerator.java
Created July 2, 2018 07:02 — forked from caoxudong/TokenGenerator.java
tomcat中生成JSESSIONID的代码
package com.meiliao.ops.utils.security;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

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.