Skip to content

Instantly share code, notes, and snippets.

View whatvn's full-sized avatar

Hung whatvn

View GitHub Profile
@whatvn
whatvn / mfsmonitor.py
Created February 14, 2012 03:17
Nagios script for Moosefs monitoring
#!/usr/bin/env python
# Nagios monitoring script for moosefs master server
# Based on mfscgiserv from moosefs author
# hungnv 13022012
import socket
import struct
import sys
@whatvn
whatvn / timeout.sh
Created February 24, 2012 09:19
kill a proc after timeout
#!/bin/bash
#
# The Bash shell script executes a command with a time-out.
# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal
# is blocked, then the subsequent SIGKILL (9) terminates it.
#
# Based on the Bash documentation example.
# Hello Chet,
# please find attached a "little easier" :-) to comprehend
@whatvn
whatvn / zsparse.py
Created March 2, 2012 03:10
ZS Parser
#!/usr/bin/env python
# hungnv
import csv
L0 = [ x[0] for x in csv.reader(open('ZS_SOURCE.csv','r')) ]
L1 = [ x[1] for x in csv.reader(open('ZS_SOURCE.csv','r')) ]
L2 = [ x[2] for x in csv.reader(open('ZS_SOURCE.csv','r')) ]
L3 = [ x[3] for x in csv.reader(open('ZS_SOURCE.csv','r')) ]
#FL = []
for i in xrange(len(L1)):
@whatvn
whatvn / heath_check.py
Created May 8, 2012 04:09
This is what I think my application will use to perform heathcheck for http server
def heart_check(target):
global last_check
if int(time() - last_check) > 5:
logger(ctime() + ": Perform heart check")
p = re.compile("[a-z0-9-.]*?\.[a-z0-9]+$")
domain_tld = p.findall(target)[0]
conn = HTTPConnection(domain_tld, timeout = 5)
try:
accepted_responses = (404, 302, 304, 301, 200)
conn.request('HEAD', '/')
@whatvn
whatvn / gist:2961023
Created June 20, 2012 17:19 — forked from joskid/gist:1658620
tutorial ml codes
@whatvn
whatvn / read_mfs_write_qfs.py
Created November 17, 2012 04:31
Read from MooseFS, write to QFS
"""
- sequence read
- sequence write
"""
import os
import sys
import time
import errno
@whatvn
whatvn / read_mfs_write_qfs_multithread.py
Created November 17, 2012 06:14
Read from MooseFS, write to QFS using multithreading
"""
- sequence read
- sequence write
"""
import os
import sys
import time
import errno
@whatvn
whatvn / Usage
Last active August 29, 2015 14:03
script based on rasterize.js (phantomjs) to take screenshot of a given website (not full page), code listed here I just copy from many website and combined into working one.
export QTWEBKIT_PLUGIN_PATH=/usr/lib/browser-plugins:/usr/lib/flash-plugin:/usr/lib/mozilla/plugin:/usr/lib64/flash-plugin:/usr/lib64/mozilla/plugins:/usr/lib64/opera/plugins; export LIBXCB_ALLOW_SLOPPY_LOCK=1;xvfb-run --server-args="-screen 0, 1280x800x24" phantomjs --load-plugins=yes ambientscreenshot.js http://google.com /data/imgs/google.png
@whatvn
whatvn / cacti_memcache_multiport.xml
Created August 4, 2014 10:40
Cacti memcache template multiport
<cacti>
<hash_020016b09df6b35e243cb959f0fac2a1de48f2>
<name>Memcached Server - Multiport</name>
<graph_templates>hash_000016ddd8df13eea701e8e0515081995fcfd8|hash_0000169298c486308a406a19d77e68e367fd53|hash_000016540aaa04728046da9eb5fc3b17931aee|hash_0000168fc8202d6b446dfa6b9cab4ab8b6ff84|hash_0000166ea53ffa66406a3d46fcbb4cb85ce5ae|hash_000016fddba8d561e012a395cbf909deb4d1da</graph_templates>
<data_queries></data_queries>
</hash_020016b09df6b35e243cb959f0fac2a1de48f2>
<hash_000016ddd8df13eea701e8e0515081995fcfd8>
<name>Memcached - Bytes Used - Multiport</name>
<graph>
<t_title>on</t_title>
public void process(String topic, ConsumerConnector consumer) {
Map<String, Integer> topicCountMap = new HashMap<>();
topicCountMap.put(topic, new Integer(1));
Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap);
KafkaStream<byte[], byte[]> stream = consumerMap.get(topic).get(0);
ConsumerIterator<byte[], byte[]> it = stream.iterator();
while (it.hasNext()) {
try {