Author: ronald

  • X11VNC

    This is a good startup command switches for x11vnc. I still need to figure out the sharing of clipboard.

    # Create a password file
    x11vnc -storepasswd
    
    # Startup X11VNC with swithes
    x11vnc -forever -noxdamage -bg -geometry 1600x900 -o "/home/[USER]/.x11vnc.log.deba55:5900" -rfbauth /home/[USER]/.vnc/passwd
  • Docker

    Images

    # List all docker images
    docker images
    or
    docker image ls
    
    # Install / get from docker hub
    docker pull linode/lamp 
    
    docker run --name ronspin -p 80:80 -t -i linode/lamp /bin/bash
    docker run --rm  -v "$PWD" -w /usr/src/myapp php:7.0-cli cat /etc/*-release
    
    docker exec -it ronspin /bin/bash
    
    # Cleanup Dangling images 
    docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

    Containers

    # Docker list all containers
    docker ps -a
    
    # Restart a down/exited container?
    docker start [a container id, example ec6163c5a5b1]
    
    # Stop a container
    docker stop [a container id, or name]
    
    # Delete a container
    docker rm [a container id, example ec6163c5a5b1]
    
    # Exit from container interactive mode and let it run as daemon
    ctrl+p, ctrl+q
    
    # Copy from a container to host
    docker cp :/file/path/within/container /host/path/target
  • MongoDB notes

    Executing a MongoDB query from command line

    mongo -u 'MyUsername' -p 'MyPassword' --eval 'db.getCollection("fs.files").find({"_id": ObjectId("fffffffff")});' '127.0.0.1:27017/MyDBName' 

  • List open or listening ports

    MacOS

    lsof -nP -i4TCP

    RedHat/Centos7

    netstat -tulpn

  • MongoDB Notes

    When using MongoDB to store files, we have 2 collections:
    1. The place where MongoDB store the file metadata: store.files
    2. Ans place where MongoDB store the file content: store.chunks

    Depending on the size of the file, one entry in store.files can points to many entries in store.chunks. The bigger the file, the more entry you’ll encounter.


    // Show all/ list all entries from store.files
    db.getCollection('store.files').find({});

    // Show only a particular entry from store.files
    db.getCollection('store.files').find({ _id : ObjectId("5b02d232cbce1d07e08401c7")});

    // The same can be used for store chunks.
    db.getCollection('store.chunks').find({});

    The metadata/fields in the store.files can be expanded during query runtime (not saved into the MongoDB, only displayed during runtime)

    db.getCollection('store.files').aggregate([
    { $match: { _id : ObjectId("5b02d232cbce1d07e08401c7")} },
    { $addFields:{'key_reference':'1234'}}
    ]);

    Or we do an update into store.files which will be saved into the MongoDB

    db.getCollection('store.files').updateMany({ _id : ObjectId("5b02d232cbce1d07e08401c7")},{$set:{'key_reference':'1234'}});

  • CentOS 6 repo Settings

    To fix repo settings in CentOS 6

    1. make sure there is no proxy or funny settings in
    vi /etc/yum.conf

    2. There are a couple of files within /etc/yum.repos.d/. Make sure the url are correct (accessible) and enabled=1
    ll /etc/yum.repos.d/

    3. Cleanup the repo, list and retest
    yum –enablerepo=base clean metadata;
    yum repolist all
    yum search java-1.8.0-openjdk

  • Show Linux Partition Tree Mountpoint and If SSD


    lsblk -o TYPE,NAME,KNAME,UUID,MOUNTPOINT,SIZE,ROTA

  • Setting log4j log level programmatically

    private static void setupLog4j() { 
      System.out.println(“setupLog4j”); 
      BasicConfigurator.resetConfiguration(); 
      // Start clean. Logger.getRootLogger().removeAllAppenders(); 
      // Create appender ConsoleAppender console = new ConsoleAppender(); 
      // Configure the appender String PATTERN = “%d –[ %p ] %l: %m%n”; 
      console.setLayout(new PatternLayout(PATTERN)); 
      console.activateOptions(); console.setName(“stdout”); 
      Logger.getRootLogger().setLevel(Level.DEBUG); 
      BasicConfigurator.configure(console); 
      LOG = Logger.getLogger(MinerTest.class); 
    }
    

  • Print java stack trace from anywhere

    Need to know which code call a specific location?
    Dump the stack trace:

    LOG.trace(ExceptionUtils.getStackTrace(new Throwable()));

  • Knowing you exception class name

    To know what is your exception class name, in case you want to have a more specific catch.

    } catch (Exception e){
    LOG.error("SQL error when processing " + requestId+". Exception class:"+ e.getClass().getCanonicalName());
    throw(e);
    }