Search This Blog

Split large file and assemble the parts

split -b 256mb large-file.tgz large-file.tgz.
cat large-file.tgz.* > /path/to/output/large-file.tgz

Thread-safe, fixed-size map remove the eldest element automatically

    public static final int MAX_SIZE = 1000;
    Map map = Collections.synchronizedMap(new LinkedHashMap() {
       private static final long serialVersionUID = 12345L; 
       @Override
       protected boolean removeEldestEntry(Entry eldest) {
           return size() > MAX_SIZE;
       }               
    });



See also stackoverflow

  • https://stackoverflow.com/a/28654664
  • https://stackoverflow.com/a/1963881

Unlock Telstra 4G My Pocket WIFI LITE (ZTE MF90)

  1. Download and install the driver
    • Download ZTE MF90 driver to a Windows 7 PC, extract the zip package
    • Turn the device on, and connect it to Windows 7 PC via USB cable. It should detect the device and install the driver. For me it does not find the driver automatically. Instead it shows "ZTE xxx installation" unsuccessfully.
    • Go to Control Panel then search and open Device Manager, you should see three unknown devices with name "ZTE xxx xxx xxx". Right click each unknown device, then select Update drivers, then select the directory where the ZTE MF90 driver was extracted to. NOTE: You need to update drivers for each unknown device.
  2. Download and run DCCRAP
    • Google DCCRAP, download and make sure it does NOT contain virus (you can check the file using VirusTotal).
    • Run DCCRAP on the Windows 7 PC, select ZTE data cards then Auto detect the device. Once the device is detected, you can click the Unlock button to unlock it.
  3. Set to use non-telstra APN
    • Put a telstra sim into the device and turn it on
    • Login the web portal in 192.168.0.1, using password: password
    • Set apn to vfprepaymbb for Vodafone

Command to mount smb share on Mac OS X

enter password:
mkdir -p ~/smb-share
mount_smbfs //'domain;user'@smb-server.your.org/smb-share ~/smb-share
or with password in command:
mkdir -p ~/smb-share
mount_smbfs //'domain;user:password'@smb-server.your.org/smb-share ~/smb-share

Wrap Java as Mac App bundle

See https://github.com/federkasten/appbundle-maven-plugin

NOTE:

  • dictionaryFile and iconFile must be in src/main/resources directory, their values in configuration must be only the file names (without path).
  • jrePath must be absolute path.

generate Python API DOC using Sphinx

  1. Install Sphinx
  2. Run sphinx-quickstart to generate the doc source
    cd /path/to/my-python-project
    mkdir doc
    cd doc
    sphinx-quickstart
    
            autodoc: automatically insert docstrings from modules: Y
    
  3. edit conf.py, uncomment and modify the following lines(assume python modules are in ../src/):
    import os
    import sys
    sys.path.insert(0, os.path.abspath('../src'))
    
    
    
  4. Run sphinx-apidoc to generate reST files for specified modules (in ../src/):
    sphinx-apidoc -o . ../src
    
  5. Generate html api doc:
    make html
    

Mediaflux Plugin Development: Create dataset from HTTP URL (with Basic Auth)

The example shows how to create a dataset asset from a password protected URL (Basic HTTP Auth).

Java: HTTP GET data from URL (with basic HTTP Auth)

The example shows how to do HTTP GET to download a file from URL. It also include an example to call Mediaflux client api to create a dataset from the url by piping the streams.

encode Base64 string in command line

  • Encode base64 string:
    echo -n Secret | base64
    
  • Decode base64 string:
    echo -n U2VjcmV0 | base64 -D
    

Note:

When encoding, -n must be specified. otherwise, a newline character will always be appended, which will cause unexpected result.

See http://askubuntu.com/questions/694216/base64-encode-is-giving-ambigious-results

Maven: skip unit tests

<properties>
    <maven.test.skip>true</maven.test.skip>
</properties>

make Java HttpURLConnection support MKCOL PROFIND and other non-standard HTTP methods

    private static void setRequestMethod(HttpURLConnection conn, String method) throws Throwable {
        try {
            conn.setRequestMethod(method);
        } catch (ProtocolException e) {
            Class<?> c = conn.getClass();
            Field methodField = null;
            Field delegateField = null;
            try {
                delegateField = c.getDeclaredField("delegate");
            } catch (NoSuchFieldException nsfe) {

            }
            while (c != null && methodField == null) {
                try {
                    methodField = c.getDeclaredField("method");
                } catch (NoSuchFieldException nsfe) {

                }
                if (methodField == null) {
                    c = c.getSuperclass();
                }
            }
            if (methodField != null) {
                methodField.setAccessible(true);
                methodField.set(conn, method);
            }

            if (delegateField != null) {
                delegateField.setAccessible(true);
                HttpURLConnection delegate = (HttpURLConnection) delegateField.get(conn);
                setRequestMethod(delegate, method);
            }
        }
    }

Multi-threading in Mediaflux Plugin Service

package wxyz.mf.plugin.services;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import arc.mf.plugin.PluginLog;
import arc.mf.plugin.ServiceExecutor;
import arc.xml.XmlDoc.Element;
import arc.xml.XmlWriter;
import wxyz.mf.plugin.util.MultiThreadPluginService;

public class SvcTest extends MultiThreadPluginService<Integer> {

    private Interface _defn;

    public SvcTest() {
        _defn = new Interface();
    }

    @Override
    public Access access() {
        return ACCESS_ACCESS;
    }

    @Override
    public Interface definition() {
        return _defn;
    }

    @Override
    public String description() {

        return "Test multithreading.";
    }

    @Override
    public String name() {
        return "omics.test";
    }

    @Override
    protected void consume(ServiceExecutor executor, Integer input, PluginLog log) throws Throwable {
        Thread.sleep(1000);
        String uuid = executor.execute("server.uuid").value("uuid");
        if (input == 15) {
            log.add(PluginLog.WARNING, "#8: Mock Exception for value 15.");
            throw new Exception("Mock Exception for value 15.");
        }
        System.out.println(Thread.currentThread().getName() + " consumed: " + input);
        System.out.println(Thread.currentThread().getName() + " uuid: " + uuid);
    }

    @Override
    protected Collection<Integer> produce(Element args, Inputs in, Outputs out, XmlWriter w,
            Map<String, Object> intermediateResults) throws Throwable {
        List<Integer> inputs = new ArrayList<Integer>(100);
        for (int i = 0; i < 20; i++) {
            inputs.add(i);
        }
        return inputs;
    }

}

HTML table fill up the whole page

<table style="width:100%; height:100%; position:absolute; top:0; bottom:0; left 0; right:0;" border="0" cellspacing="1" cellpadding="3">
    <tr id="content" style="height: 100%;">
        <td align="center">Content</td>
    </tr>
    <tr id="footer" style="height:28px;">
        <td align="center">footer</td>
    </tr>
</table>

DICOM Modalities

ModalityDescription
ARAutorefraction
ASMTContent Assessment Results
AUAudio
BDUSBone Densitometry (ultrasound)
BIBiomagnetic imaging
BMDBone Densitometry (X-Ray)
CRComputed Radiography
CTComputed Tomography
CTPROTOCOLCT Protocol (Performed)
DGDiaphanography
DOCDocument
DXDigital Radiography
ECGElectrocardiography
EPSCardiac Electrophysiology
ESEndoscopy
FIDFiducials
GMGeneral Microscopy
HCHard Copy
HDHemodynamic Waveform
IOIntra-Oral Radiography
IOLIntraocular Lens Data
IVOCTIntravascular Optical Coherence Tomography
IVUSIntravascular Ultrasound
KERKeratometry
KOKey Object Selection
LENLensometry
LSLaser surface scan
MGMammography
MRMagnetic Resonance
NMNuclear Medicine
OAMOphthalmic Axial Measurements
OCTOptical Coherence Tomography (non-Ophthalmic)
OPOphthalmic Photography
OPMOphthalmic Mapping
OPTOphthalmic Tomography
OPVOphthalmic Visual Field
OSSOptical Surface Scan
OTOther
PLANPlan
PRPresentation State
PTPositron emission tomography (PET)
PXPanoramic X-Ray
REGRegistration
RESPRespiratory Waveform
RFRadio Fluoroscopy
RGRadiographic imaging (conventional film/screen)
RTDOSERadiotherapy Dose
RTIMAGERadiotherapy Image
RTPLANRadiotherapy Plan
RTRECORDRT Treatment Record
RTSTRUCTRadiotherapy Structure Set
RWVReal World Value Map
SEGSegmentation
SMSlide Microscopy
SMRStereometric Relationship
SRSR Document
SRFSubjective Refraction
STAINAutomated Slide Stainer
TGThermography
USUltrasound
VAVisual Acuity
XAX-Ray Angiography
XCExternal-camera Photography

Modify Mediaflux mflux package to install it into non-default schema

  1. copy the mflux.zip from /opt/mediaflux/ext/packages/ to /tmp
    cp /opt/mediaflux/ext/packages/mflux.zip /tmp/
    mkdir /tmp/mfpkg; cd /tmp/mfpkg; unzip /tmp/mflux.zip
  2. edit __install.tcl file
    vi /tmp/mfpkg/__install.tcl
    # HTTP processors:
    
    if { [info exists host] } {
        
        if { [xvalue exists [http.processor.exists :host $host :url /mflux]] == "false" } { 
          http.processor.create :host $host :app mflux :url /mflux :type asset :translate /www :authentication < :domain $domain :user $user > :view mflux-www
        }
    
        # Set the servlet entry points for the HTTP processors.
        http.servlets.set :host $host :url /mflux \
           :servlet -path portal.mfjp -default true arc.mflux.main \
           :servlet -path icon.mfjp arc.mflux.icon \
           :servlet -path iptile.mfjp arc.mflux.image.pyramid.tile \
           :servlet -path meta.mfjp arc.mflux.meta \
           :servlet -path content.mfjp arc.mflux.content \
           :servlet -path share.mfjp arc.mflux.share \
           :servlet -path output.mfjp arc.mflux.session.output \
           :servlet -path execute.mfjp arc.mflux.execute \
           :servlet -path transcode.mfjp arc.mflux.transcode \
           :servlet -path aterm.jar arc.mflux.aterm \
           :servlet -path aar.jar arc.mflux.aar
           
    } else {
    
        if { [xvalue exists [http.processor.exists :url /mflux]] == "false" } { 
          http.processor.create :app mflux :url /mflux :type asset :translate /www :authentication < :domain $domain :user $user > :view mflux-www
        }
    
        # Set the servlet entry points for the HTTP processors.
        http.servlets.set :url /mflux \
           :servlet -path portal.mfjp -default true arc.mflux.main \
           :servlet -path icon.mfjp arc.mflux.icon \
           :servlet -path iptile.mfjp arc.mflux.image.pyramid.tile \
           :servlet -path meta.mfjp arc.mflux.meta \
           :servlet -path content.mfjp arc.mflux.content \
           :servlet -path share.mfjp arc.mflux.share \
           :servlet -path output.mfjp arc.mflux.session.output \
           :servlet -path execute.mfjp arc.mflux.execute \
           :servlet -path transcode.mfjp arc.mflux.transcode \
           :servlet -path aterm.jar arc.mflux.aterm \
           :servlet -path aar.jar arc.mflux.aar
    
    }
    
  3. Re-package:
    cd /tmp/mfpkg; zip -r ../mflux-1.zip ./*
  4. Install the modified package in Aterm:
    package.install :in file:/tmp/mflux-1.zip :arg -name host daris.vicnode.org.au