19 May 2012
by feinanin Technology
ffmpeg is a very fast video and audio converter that can also grab from a live audio/video source. It can also convert between arbitrary sample rates and resize video on the fly with a high quality polyphase filter.
The following CLI will chop off the first 30 seconds of the video and record 4-minute video to the output file “cutted.mp4″.
1
| ffmpeg -i ~/Videos/M4H02608.MP4 -vcodec copy -ss 00:00:30 -t 00:04:00 cutted.mp4 |
19 May 2012
by feinanin Technology
Apache Solr is a fast, open-source search solution. The following is to walk through setting up multi-core Solr with Apache Tomcat.
Apacha Solr requires Tomcat, so the first step, install the Tomcat server:
1
| sudo apt-get install tomcat6 |
Next you’ll want to get Solr and extract it to a temporary directory:
2
3
4
5
| mkdir -p ~/tmp/solr/
cd ~/tmp/solr/
wget http://apache.ziply.com/lucene/solr/3.6.0/apache-solr-3.6.0.tgz
tar xzvf apache-solr-3.6.0.tgz |
All the solr cores and indexes will go in /var/solr:
6
| sudo mkdir -p /var/solr |
Copy the Solr webapp and the example multicore configuration files:
7
8
9
| sudo cp apache-solr-3.6.0/dist/apache-solr-3.6.0.war /var/solr/solr.war
sudo cp -R apache-solr-3.6.0/example/multicore/* /var/solr/
sudo chown -R tomcat6 /var/solr/ |
Now just need to point Catalina at Solr:
10
11
| echo -e '<Context docBase="/var/solr/solr.war" debug="0" privileged="true" allowLinking="true" crossContext="true">\n<Environment name="solr/home" type="java.lang.String" value="/var/solr" override="true" />\n</Context>' | sudo tee -a /etc/tomcat6/Catalina/localhost/solr.xml
echo 'TOMCAT6_SECURITY=no' | sudo tee -a /etc/default/tomcat6 |
I edited the init script (/etc/init.d/tomcat6) to set solr.home, pointing it at /var/solr. I made this change near the top of the file other environment vars are set up:
12
| JAVA_OPTS="$JAVA_OPTS -Dsolr.home=/var/solr" |
Restart Tomcat6 and luxuriate in your newfound power:
13
| sudo /etc/init.d/tomcat6 restart |
Navigate to http://localhost:8080/solr/ – you should see it up and running.
23 Apr 2012
by feinanin Technology
In Linux programming, users can convert encoding for a string buffer from one to another. The following example convert the input string from UTF-16 to UTF-8. The input is char** in_content, a pointer to pointer of the string. The string size is size_t in_content_size. The conversion will be made in-place and output would be written back to char** in_content.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| #include <iconv.h>
size_t Convert_UTF16_To_UTF8(char** in_content, size_t in_content_size)
{
iconv_t icv;
char* in_buf = malloc(in_content_size);
char* in;
size_t in_sz;
char* out_buf = malloc(in_content_size);
char* out;
size_t out_sz;
icv = iconv_open("UTF-8", "UTF-16");
memcpy(in_buf, *in_content, in_content_size);
in = in_buf;
in_sz = in_content_size;
out = (char*) out_buf;
out_sz = in_content_size;
size_t ret = iconv(icv, &in, &in_sz, &out, &out_sz);
strcpy(*in_content, out_buf);
free(in_buf);
free(out_buf);
iconv_close(icv);
return ret;
} |
15 Dec 2011
by feinanin Technology
In your bash, do the following
1
| calc(){ awk "BEGIN{ print $* }" ; } |
and then do the following:
or
you can put this in your ~/.bash_profile too
09 Dec 2011
by feinanin Technology
Traceroute is a command which can show you the path a packet of information takes from your computer to one you specify. It will list all the routers it passes through until it reaches its destination, or fails to and is discarded. In addition to this, it will tell you how long each hop from router to router takes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| [root@sjc14-esx2-vm3 ~]# traceroute iph.csi2.c3w.tv
traceroute to iph.csi2.c3w.tv (192.118.77.180), 30 hops max, 40 byte packets
1 172.29.96.1 (172.29.96.1) 3.150 ms 3.141 ms 3.135 ms
2 sjc14-00lab-gw1-gig1-4.cisco.com (172.24.114.181) 3.120 ms 3.105 ms 3.094 ms
3 sjc12-lab4-gw1-ten6-7.cisco.com (172.24.95.29) 3.086 ms 3.078 ms 3.067 ms
4 sjc5-sbb4-gw1-ten8-6.cisco.com (171.71.241.174) 3.049 ms 3.045 ms 3.037 ms
5 sjc12-rbb-gw4-ten7-4.cisco.com (171.71.241.254) 3.003 ms 2.997 ms 2.988 ms
6 sjc12-gb1-ten2-2.cisco.com (10.112.4.157) 2.974 ms 3.924 ms 3.914 ms
7 capnet-rtp10-sjc12-10ge.cisco.com (10.112.4.162) 78.649 ms 78.646 ms 79.351 ms
8 rtp5-rbb-gw1-ten4-6.cisco.com (10.112.4.106) 81.145 ms 81.143 ms 81.863 ms
9 rtp5-gb2-ten2-1.cisco.com (10.112.3.77) 79.921 ms 79.917 ms 79.911 ms
10 capnet-amsidc-rtp5-oc48.cisco.com (10.112.4.114) 167.285 ms 167.277 ms 167.263 ms
11 amsidc-rbb-gw2-ten2-1.cisco.com (10.112.4.202) 167.197 ms 167.194 ms 166.839 ms
12 amsidc-wan-gw1-ten6-2.cisco.com (144.254.78.14) 168.174 ms 167.671 ms 167.639 ms
13 amsidc-cw-pe1-oc48.cisco.com (10.61.40.18) 167.006 ms 167.087 ms 167.075 ms
14 ntn01-wan-gw1-ser1-0.cisco.com (144.254.136.193) 256.178 ms 256.308 ms 256.298 ms
15 ntn01-bb-gw2-gig2-7.cisco.com (64.103.115.205) 255.074 ms 254.828 ms 255.553 ms
16 ntn01-corp-gw1-gig0-2.cisco.com (64.103.116.14) 254.310 ms 254.302 ms 254.297 ms
17 ntn01-dmzbb-gw1-gig2-43.cisco.com (192.118.78.166) 260.572 ms 260.568 ms 257.431 ms
18 ntn01-dmznet-gw1-gig1-1.cisco.com (192.118.78.86) 254.664 ms 254.664 ms 254.655 ms
19 ntn01-dmzlab-gw1-gig1-1.cisco.com (192.118.76.26) 256.993 ms 257.295 ms 256.258 ms
20 csi-scp-dmz-gw.cisco.com (192.118.76.106) 257.160 ms 257.138 ms 256.874 ms
21 csi-scp-dmz-gw.cisco.com (192.118.76.106) 257.300 ms !X * * |