2016年12月23日 星期五

CentOS 7.3 Installation on Virtual Box



Download Minimal ISO
https://www.centos.org/download/
CentOS-7-x86_64-Minimal-1611.iso
Never Succeed

Download 6.9 instead!
CentOS-6.9-x86_64-minimal.iso         29-Mar-2017 02:31  408M 


See you next time

2016年12月22日 星期四

Simple Logger Facade SLF4J Java 8 on Linux

Main Reference
http://www.slf4j.org/manual.html
http://ifeve.com/slf4j-manual/

Confirm your JDK
[ricky@thrift2 SimpleLoggingFacade]$ javac -version
javac 1.8.0_111

Download it to ~/SimpleLoggingFacade
wget http://www.slf4j.org/dist/slf4j-1.7.22.tar.gz
tar zxvf slf4j-1.7.22.tar.gz

HelloWorld.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloWorld {
  public static void main(String[] args) {
    Logger logger = LoggerFactory.getLogger(HelloWorld.class);
    logger.info("Hello World");
  }
}

Error 1 : org.slf4j does not exist
[ricky@thrift2 SimpleLoggingFacade]$ javac HelloWorld.java
HelloWorld.java:1: error: package org.slf4j does not exist
import org.slf4j.Logger;
                ^
HelloWorld.java:2: error: package org.slf4j does not exist
import org.slf4j.LoggerFactory;
                ^
HelloWorld.java:6: error: cannot find symbol
    Logger logger = LoggerFactory.getLogger(HelloWorld.class);
    ^
  symbol:   class Logger
  location: class HelloWorld
HelloWorld.java:6: error: cannot find symbol
    Logger logger = LoggerFactory.getLogger(HelloWorld.class);
                    ^
  symbol:   variable LoggerFactory
  location: class HelloWorld
4 errors

Solution 1: org.slf4j does not exist
javac -cp ".:./slf4j-1.7.22/slf4j-api-1.7.22.jar" HelloWorld.java

Error 2: Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
[ricky@thrift2 SimpleLoggingFacade]$ java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
        at HelloWorld.main(HelloWorld.java:6)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

Solution 2 : Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
[ricky@thrift2 SimpleLoggingFacade]$ java -cp ".:./slf4j-1.7.22/slf4j-api-1.7.22.jar" HelloWorld
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Error 3: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

Solution 3: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
java -cp ".:./slf4j-1.7.22/slf4j-api-1.7.22.jar:./slf4j-1.7.22/slf4j-simple-1.7.22.jar" HelloWorld

[main] INFO HelloWorld - Hello World

Solution 3 using simple:
java -cp ".:./slf4j-1.7.22/slf4j-api-1.7.22.jar:./slf4j-1.7.22/slf4j-simple-1.7.22.jar" HelloWorld
[main] INFO HelloWorld - Hello World

Solution 3 using jdk14:
java -cp ".:./slf4j-1.7.22/slf4j-api-1.7.22.jar:./slf4j-1.7.22/slf4j-jdk14-1.7.22.jar" HelloWorld

Dec 22, 2016 3:52:36 PM HelloWorld main
INFO: Hello World

Solution 3 using nop:
java -cp ".:./slf4j-1.7.22/slf4j-api-1.7.22.jar:./slf4j-1.7.22/slf4j-nop-1.7.22.jar" HelloWorld

Solution 3 using JCL:
wget http://apache.website-solution.net//commons/logging/binaries/commons-logging-1.2-bin.tar.gz

tar zxvf commons-logging-1.2-bin.tar.gz
java -cp ".:./slf4j-1.7.22/slf4j-api-1.7.22.jar:./slf4j-1.7.22/slf4j-jcl-1.7.22.jar:./commons-logging-1.2/commons-logging-1.2.jar" HelloWorld
Dec 22, 2016 3:51:22 PM HelloWorld info
INFO: Hello World

Solution 3 using log4j 1.2:
echo "Need to download log4j-1.2.17.tar.gz"
echo "Do not download apache-log4j-2.7-bin.tar.gz"
wget http://apache.01link.hk/logging/log4j/1.2.17/log4j-1.2.17.tar.gz

tar zxvf log4j-1.2.17.tar.gz

java -cp ".:./slf4j-1.7.22/slf4j-api-1.7.22.jar:./slf4j-1.7.22/slf4j-log4j12-1.7.22.jar:./apache-log4j-1.2.17/log4j-1.2.17.jar" HelloWorld

Error 4 : WARN No appenders could be found for logger (HelloWorld)
log4j:WARN No appenders could be found for logger (HelloWorld).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Solution 4 : WARN No appenders could be found for logger (HelloWorld)
vi log4j.properties
log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%t %-5p %c{2} - %m%n

Solution 3 using log4j 1.2 alternative (simpler):

mkdir lib
cp ./slf4j-1.7.22/slf4j-api-1.7.22.jar ./lib/
cp ./slf4j-1.7.22/slf4j-log4j12-1.7.22.jar ./lib/
wget http://apache.01link.hk/logging/log4j/1.2.17/log4j-1.2.17.tar.gz
tar zxvf log4j-1.2.17.tar.gz
cp ./apache-log4j-1.2.17/log4j-1.2.17.jar ./lib/
java -cp ".:./lib/*" HelloWorld

a
sdas

2016年12月19日 星期一

Virtualbox Extension Pack on Linux and using USB Device on Guest Instance

sudo vboxmanage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-5.1.10-112026.vbox-extpack

sudo usermod -a -G vboxusers ricky

instance > Settings > USB > Enable USB Controller + USB 2.0

MongoDB Python pymongo

Install Anaconda
https://anaconda.org/anaconda/pymongo
conda install -c anaconda pymongo=3.3.0
from pymongo import MongoClient



MongoDB Queries
db.getCollection('SHCU_1Min_History').distinct( "Date", { $or: [ {"AskPrice1":{$gt:1.79e+308}}, {"AskPrice2":{$gt:1.79e+308}}, {"BidPrice1":{$gt:1.79e+308}}, {"BidPrice2":{$gt:1.79e+308}} ] } )

2016年12月2日 星期五

Wireshark and tshark Examples on Windows and Linux

Python
import datetime
a = datetime.timedelta(seconds=25293)
str(a)
'7:01:33'
b = datetime.timedelta(seconds=25464)
str(b)
'7:04:24'


Linux

tshark -r PM.pcap -Y '(frame.time >= "Nov 30, 2016 07:01:33") && (frame.time <= "Nov 30, 2016 7:04:24")' -w out.pcap

[quantprod@hkoffice083 trial]$ capinfos PM.pcap
File name:           PM.pcap
File type:           Wireshark/tcpdump/... - pcap
File encapsulation:  Ethernet
Packet size limit:   file hdr: 65535 bytes
Number of packets:   3,096 k
File size:           2,492 MB
Data size:           2,443 MB
Capture duration:    15142 seconds
Start time:          Wed Nov 30 05:21:56 2016
End time:            Wed Nov 30 09:34:18 2016
Data byte rate:      161 kBps
Data bit rate:       1,290 kbps
Average packet size: 789.02 bytes
Average packet rate: 204 packets/sec
SHA1:                6238971ac36f2bfb990668f3889e61ec26c3769c
RIPEMD160:           689c0dbe61c95d14882d631b76d0afe3f0a3b10c
MD5:                 9cc626ffc7314bc8a9f4f5e03c81ff5d
Strict time order:   True


2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...