Skip to content

Instantly share code, notes, and snippets.

View jsvisa's full-sized avatar
🏠
Working from home

Delweng jsvisa

🏠
Working from home
View GitHub Profile
@jsvisa
jsvisa / observer.md
Last active August 29, 2015 14:27 — forked from pnc/observer.md
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
@jsvisa
jsvisa / kafka-jmx.json
Created May 17, 2016 06:22
Kafka Jmxtrans config sample
{
"servers" : [
{
"queries" : [
{
"resultAlias" : "jvmMemory",
"obj" : "java.lang:type=Memory",
"attr" : [
"HeapMemoryUsage",
"NonHeapMemoryUsage"
@jsvisa
jsvisa / bad_utf8.exs
Created May 20, 2016 12:19
Bad UTF8 in Elixir
defmodule Check do
def is_utf8?(""), do: true
def is_utf8?(<< char :: size(8), rest :: binary >>) when char <= 0x7f, do: is_utf8?(rest)
def is_utf8?(<< f :: size(8), s :: size(8), rest :: binary >>)
when f >= 0xc0 and f <= 0xdf and # 110* ****
s >= 0x80 and s <= 0xbf do # 10** ****
is_utf8?(rest)
end

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.

@jsvisa
jsvisa / idc-init.sh 
Created July 18, 2017 03:15
IDC testing script
#!/bin/sh
## package install
cd /tmp
wget -c https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.4.1.linux-x64.tar.gz
tar zxvf grafana-4.4.1.linux-x64.tar.gz -C /usr/local && mv /usr/local/grafana{-4.4.1,}
wget -c https://dl.influxdata.com/influxdb/releases/influxdb-1.2.4_linux_amd64.tar.gz
tar xvfz influxdb-1.2.4_linux_amd64.tar.gz -C /usr/local && mv /usr/local/influxdb{-1.2.4-1,}
wget -c https://dl.influxdata.com/telegraf/releases/telegraf-1.3.4_linux_amd64.tar.gz
tar xvfz telegraf-1.3.4_linux_amd64.tar.gz -C /usr/local && mv /usr/local/telegraf{-1.3.4,}
@jsvisa
jsvisa / idc-grafana-basic.json
Created July 18, 2017 03:25
Grafana dashboard for IDC testing
{
"__inputs": [
{
"name": "DS_INFLUXDB",
"label": "influxdb",
"description": "",
"type": "datasource",
"pluginId": "influxdb",
"pluginName": "InfluxDB"
}
@jsvisa
jsvisa / picfetcher.go
Created October 19, 2017 01:11
picfetcher.go
package main
import (
"bufio"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
@jsvisa
jsvisa / load-ipvs.sh
Created November 14, 2017 12:24
load-ipvs.sh
#!/bin/bash
# Author: Delweng Zheng <delweng@gmail.com>
if $(lsmod | grep -q "ip_vs"); then
exit 0
fi
if [ -f /etc/redhat-release ]; then
RELEASE="centos"
elif cat /etc/issue | grep -Eqi "debian"; then
@jsvisa
jsvisa / hbase.rest.scanner.filters.md
Created February 8, 2018 08:18 — forked from stelcheck/hbase.rest.scanner.filters.md
HBase Stargate REST API Scanner Filter Examples

Stargate Scanner Filter Examples

Introduction

So yeah... no documentation for the HBase REST API in regards to what should a filter look like...

So I installed Eclipse, got the library, and took some time to find some of the (seemingly) most useful filters you could use. I'm very green at anything regarding HBase, and I hope this will help anyone trying to get started with it.

What I discovered is that basically, attributes of the filter object follow the same naming than in the documentation. For this reason, I have made the link clickable and direct them to the HBase Class documentation attached to it; check for the instantiation argument names, and you will have your attribute list (more or less).

@jsvisa
jsvisa / convert_data.py
Last active May 23, 2018 08:47
convert_data.py
# coding=utf-8
import math
import os
import random
import tensorflow as tf
import dataset_utils
import argparse
# 定义一些全局常量