Skip to content

Instantly share code, notes, and snippets.

@aleung
aleung / console-output
Created June 13, 2017 08:06
Test of [async-local-storage](https://github.com/vicanso/async-local-storage) on Node.js 8.x
Trace of ID 1
1497340609369: Received request. ID: 1
1497340609369: Step 1 1
1497340610599: Step 2 1
1497340610602: Response sent 1
-----
Trace of ID 2
1497340606575: Received request. ID: 2
1497340606575: Step 1 2
1497340612700: Step 2 2
@aleung
aleung / user.js
Last active June 8, 2017 09:26
User script to slideshow a serial of webpages in loop. https://greasyfork.org/en/scripts/30426-webpages-slideshow
// ==UserScript==
// @name Webpages slideshow
// @namespace https://github.com/aleung/
// @version 1.1.0
// @description Loop display a serial of webpages. Display time for each page can be set.
// @author Leo Liang
// @license MIT License
// @include *
// @noframes
// @require https://openuserjs.org/src/libs/sizzle/GM_config.js
@aleung
aleung / user.js
Last active November 1, 2017 03:29
Tuleap tracker enhancement. https://greasyfork.org/en/scripts/30456
// ==UserScript==
// @name Tuleap Tracker Enhance
// @namespace https://gist.github.com/aleung/3fac39dbba3351da2c62f8d4890ef3a6
// @version 0.4
// @description Toggle detail in card wall
// @author Leo Liang
// @match https://*/plugins/tracker/*
// ==/UserScript==
(function() {
/**************************************
* Header Counters in TOC
**************************************/
/* No link underlines in TOC */
.md-toc-inner {
text-decoration: none;
}
.md-toc-content {
@aleung
aleung / du.sh
Last active March 13, 2017 03:34
One line shell scripts
# size of immediate sub-folders
du -d1 -BM | sort -g
@aleung
aleung / mergelog.js
Created November 2, 2016 11:30
Merge consul agent logs which are fetched by Ansible
#!/usr/bin/env node
"use strict";
const fs = require('fs');
const readline = require('readline');
const logLineRegexp = /\s+(.+?)\[(.+?)\](.*)/;
function processFile(file, host) {
@aleung
aleung / ipaddr.es
Last active November 5, 2015 03:43
Get local IP address of specific NIC in node.js
var _ = require('lodash');
var os = require('os');
function getIpAddr(nicName) {
let ifaces = os.networkInterfaces();
let iface = _.find(ifaces[nicName], iface => { return iface.family === 'IPv4' });
return _.result(iface, 'address');
}
module.exports = _.memoize(getIpAddr);
@aleung
aleung / ActiveCountMetric.java
Created November 26, 2013 09:12
Invocation metric bases on codahale (Yammer) Metrics. 这是在Messaging性能测试时使用的metrics,记录了代码块调用的throughput(TPS,latency)和active count(并发数),数据每分钟写入csv格式文件。 用try + finally的方式对调用进行拦截检测,代码有侵入性。当时是测试使用,这样写起来最快。
public interface ActiveCountMetric {
void inc();
void dec();
}
@aleung
aleung / Scheduler
Created May 27, 2013 10:48
A simple Java scheduler, which execute scheduled tasks in current thread.
package leoliang.common;
import com.google.common.base.Preconditions;
/**
* Usage example: Run 15 times in every 250ms, begins at 5 seconds later.
*
* <pre>
Scheduler.every(250, Scheduler.TimeUnit.MILLISECOND)
.beginsAt(System.currentTimeMillis() + 5000)
@aleung
aleung / remove_conflict_non_unique_snapshots.rb
Created March 28, 2013 04:05
I have Maven (Artifactory) repository which was configured to store non-unique snapshots. When the configure was changed to store unique (with time-stamp) snapshots, if a new snapshot is deployed, there will be both unique snapshot and non-unique snapshot artifact of same version exists. If it happens, the snapshot artifact will be unable to dow…
#!/bin/env ruby
# --- Configuration ---------------------------------
$age_days = 3
# The repository to be cleaned.
$repo = 'repo-name'
$user = 'repo-admin'