Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing on kcp now

JasonWong medusar

🎯
Focusing on kcp now
Block or report user

Report or block medusar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@medusar
medusar / nginx.conf
Created Apr 12, 2019 — forked from yllan/nginx.conf
設定 nginx 使用 server sent event
View nginx.conf
location xxxx {
proxy_pass http://localhost:9000;
proxy_buffering off;
proxy_cache off;
proxy_redirect off;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@medusar
medusar / rate_limit2.py
Created Oct 30, 2018 — forked from josiahcarlson/rate_limit2.py
Regular and sliding window rate limiting to accompany two blog posts.
View rate_limit2.py
'''
rate_limit2.py
Copyright 2014, Josiah Carlson - josiah.carlson@gmail.com
Released under the MIT license
This module intends to show how to perform standard and sliding-window rate
limits as a companion to the two articles posted on Binpress entitled
"Introduction to rate limiting with Redis", parts 1 and 2:
View 0-rate-limiters.md

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.

@medusar
medusar / NestedMapFlatten.java
Created Jul 3, 2018
how to flatten a nested map in java8
View NestedMapFlatten.java
public void testFlattenMap() {
Map<String, Map<String, Long>> counters = new HashMap<>();
Map<String, Long> nested = new HashMap<>();
nested.put("inner1", 1L);
nested.put("inner2", 2L);
nested.put("inner3", 3L);
counters.put("out1", nested);
counters.put("out2", nested);
@medusar
medusar / TokenGenerator.java
Created Jul 2, 2018 — forked from caoxudong/TokenGenerator.java
tomcat中生成JSESSIONID的代码
View TokenGenerator.java
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;
@medusar
medusar / git-branch.md
Created Mar 14, 2018 — forked from yisibl/git-branch.md
在Mac、Linux 终端显示 Git 当前所在分支
View git-branch.md

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

  1. 进入你的home目录
cd ~
  1. 编辑.bashrc文件
@medusar
medusar / linux_smap_analyzer.py
Created Jan 4, 2018 — forked from LanderlYoung/linux_smap_analyzer.py
Linux /proc/<pid>/smaps analyzer python script
View linux_smap_analyzer.py
#!/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
@medusar
medusar / pom.xml
Created Nov 2, 2017 — forked from tomsoete/pom.xml
Spring Best Practices Maven Pom
View pom.xml
<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>
@medusar
medusar / sync-gitlab-projects
Last active Jul 19, 2018 — forked from JonasGroeger/sync-projects
Gitlab: Clone / Pull all projects in a group in gitlab(批量下载gitlab中的项目)
View sync-gitlab-projects
#!/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=""
@medusar
medusar / gist:e3481c7335a30e95491ed92bcdd5e000
Created Apr 6, 2017 — forked from jcarlosgarcia/gist:1621770
Set system properties via Spring XML configuration
View gist:e3481c7335a30e95491ed92bcdd5e000
<?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" />
You can’t perform that action at this time.