Skip to content

Instantly share code, notes, and snippets.

View fluency03's full-sized avatar

Chang Liu fluency03

  • London
View GitHub Profile
@fluency03
fluency03 / promise-retryer.js
Created March 16, 2017 16:31 — forked from domenic/promise-retryer.js
Generalized promise retryer
"use strict";
// `f` is assumed to sporadically fail with `TemporaryNetworkError` instances.
// If one of those happens, we want to retry until it doesn't.
// If `f` fails with something else, then we should re-throw: we don't know how to handle that, and it's a
// sign something went wrong. Since `f` is a good promise-returning function, it only ever fulfills or rejects;
// it has no synchronous behavior (e.g. throwing).
function dontGiveUp(f) {
return f().then(
undefined, // pass through success
@fluency03
fluency03 / 0.md
Created March 13, 2017 15:15 — forked from max-mapper/0.md
JS hoisting by example

JavaScript function hoisting by example

Below are many examples of function hoisting behavior in JavaScript. Ones marked as works successfuly print 'hi!' without errors.

To play around with these examples (recommended) clone them with git and execute them with e.g. node a.js

Notes on hoisting

(I may be using incorrect terms below, please forgive me)

@fluency03
fluency03 / API.md
Created March 11, 2017 20:36 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:


title: 'Leetcode Solution in Java' layout: post date: '2017-01-20 20:25' tag:

  • Leetcode
  • Java
  • Algorithms
  • Data Structure
  • Question
A
ABORT
ABS
ABSOLUTE
ACCESS
ACTION
ADA
ADD
ADMIN
AFTER
@fluency03
fluency03 / nginx-elasticsearch-proxy.conf
Created December 13, 2016 09:58 — forked from karmi/nginx-elasticsearch-proxy.conf
Route requests to ElasticSearch to authenticated user's own index with an Nginx reverse-proxy
# Run me with:
#
# $ nginx -p /path/to/this/file/ -c nginx.conf
#
# All requests are then routed to authenticated user's index, so
#
# GET http://user:password@localhost:8080/_search?q=*
#
# is rewritten to:
#
require 'json'
def parse_array obj, top, event
if obj.is_a? Array
obj.each_with_index {|oo, ii|
parse_json_array(oo, ii, top, event)
}
end
end
{
"template" : "sttx-*",
"settings" : {
"index" : {
"refresh_interval" : "5s"
}
},
"mappings" : {
"_default_" : {
"dynamic_templates" : [
input {
beats {
port => "5044"
}
}
filter {
json {
source => "message"
}
ruby {
{
"template" : "logstash-*",
"settings" : {
"index.refresh_interval" : "15s"
},
"mappings" : {
"_default_" : {
"_all" : {"enabled" : true},
"dynamic_templates" : [ {
"string_fields" : {