Skip to content

Instantly share code, notes, and snippets.

View whatvn's full-sized avatar

Hung whatvn

View GitHub Profile
@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 {
String seedUrl = "www.google.com www.blogger.com";
_logger.info("Processing url [{}]", seedUrl);
Random random = new Random();
String batchId = String.valueOf(random.nextInt());
Configuration nutchConfiguration = NutchConfiguration.create();
nutchConfiguration.set(BATCH_ID, batchId);
String solrUrl = nutchConfiguration.get(SOLR_URL);
String crawlArgs = String.format("-seedurl %s -depth 5 -topN 10", seedUrl);
// Run Crawl tool
ToolRunner.run(nutchConfiguration, new Crawler(),
@whatvn
whatvn / ffmpeg
Last active August 29, 2015 14:07
ffmpeg command output
/usr/local/bin/ffmpeg -i /tmp/input.ts -acodec libfdk_aac -vcodec libx264 -s 640x360 -b:v 1000k /tmp/output.ts 2>&1 > /tmp/output.txt
ffmpeg version 2.4.1 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct 4 2014 16:36:36 with gcc 4.6 (Ubuntu/Linaro 4.6.4-3ubuntu1)
configuration: --enable-libx264 --enable-libfdk-aac --enable-gpl --enable-nonfree --enable-shared --enable-avresample --enable-debug=3 --disable-pthreads
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libavresample 2. 1. 0 / 2. 1. 0
@whatvn
whatvn / transcoding
Created October 6, 2014 02:17
ts transcoding
int in_video_index = -1;
int in_audio_index = -1;
int return_code = ERROR;
int buffer_size;
unsigned char *exchange_area;
AVFormatContext *input_format_context = NULL;
AVFormatContext *output_format_context = NULL;
AVIOContext *io_context;
AVCodec *input_audio_codec = NULL;
AVCodec *output_audio_codec = NULL;
@whatvn
whatvn / register
Created October 6, 2014 02:26
register
rax 0x9c54f349bdfc5672 -7181848007703505294
rbx 0x1fb1a30 33233456
rcx 0x7fff40e96830 140734282426416
rdx 0x21 33
rsi 0x1 1
rdi 0x7fa70e2d0740 140355474097984
rbp 0x9c54f349bdfc5672 0x9c54f349bdfc5672
rsp 0x7fff40e967f0 0x7fff40e967f0
r8 0x0 0
r9 0x7fa70e2d0748 140355474097992
@whatvn
whatvn / scale.c
Created October 9, 2014 03:44
scale
static AVFrame* scale_encode_write_frame(AVFrame *frame, int src_w, int src_h,
int dst_w, int dst_h) {
int ret = 0;
AVFrame *scale_frame;
frame = av_frame_alloc();
if (!frame) {
av_log(NULL, AV_LOG_DEBUG, "Cannot get allocate scale frame\n");
return frame;
}
SwsContext *scale_context = NULL;
package com.firebase.utils;
import java.util.Date;
/**
* Fancy ID generator that creates 20-character string identifiers with the
* following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't
def video(gearman_worker, gearman_job):
try:
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(gearman_job.data.decode('utf-8'))
print "raw data: " + gearman_job.data
print "decode data: " + gearman_job.data.decode('utf-8')
today = datetime.date.today()
job_data = json.loads(gearman_job.data.decode('utf-8'))
....
except Exception,e: