[Tomcat] allowLinking setting (soft link)

  1. edit the file ‘Tomcat/conf/context.xml’

    change

    to

  2. restart Tomcat.

Ref. Tomcat軟連接訪問配置symbol link

Posted in Tomcat | Leave a comment

[WordPress] Avoid xmlrpc attack

  • add below code in the functions.php in your themes.
add_filter('xmlrpc_enabled', '__return_false');
  • edit .htaccess
#protect xmlrpc
<Files xmlrpc.php>
Order Deny,Allow
Deny from all
</Files>
  • delete the xmlrpc.php file

Ref. 解決WordPress被利用xmlrpc.php文件攻擊導致內存超負荷

Posted in WordPress | Leave a comment

[Java, HBase] Hostname is very important!

If the connection is failed, try to check the hdfs uri setting, it might be used hostname.

Posted in HBase, Java | Leave a comment

[Java] Connect LDAP (subdomain).

Ref. referrals & global catalog, AD Child Domain Referral Searches by Rajnish Bhatia

If you want to search all subdomain, the port of ‘PROVIDER_URL’ might be use in 3268.

Posted in Java | 1 Comment

[LDAP] Port information.

Global Catalog port: 3268
Normal LDAP port: 389

Posted in LDAP | Leave a comment

[Mac] Port in use..

lsof -n -i4TCP:$PORT | grep LISTEN

Ref: stackoverflow: Who is listening on a given TCP port on Mac OS X?

Posted in Mac | Leave a comment

[Java] Check apache poi version

Ref: The Apache POI project – Frequently Asked Questions: My code uses some new feature, compiles fine but fails when live with a “MethodNotFoundException” or “IncompatibleClassChangeError”

    ClassLoader classloader = org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
    URL res = classloader.getResource("org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
    String path = res.getPath();
    System.out.println("Core POI came from " + path);
Posted in Java | Leave a comment

[HBase] Use SingleColumnFilter in shell.

scan 'TABLENAME', {FILTER=>"(SingleColumnValueFilter('CF', ‘CQ', =, 'binary:VALUE', true, true))”}

the first true means filterIfColumnMissing
the second true means setLatestVersionOnly

Ref. Spinning Thoughts: Applying Filters in HBase shell

Posted in HBase | 2 Comments

[Sublime Text3] Enable package control

  1. Use ctrl + ` to open console. (or View->Show console)

  2. Paste the appropriate code to enable package control function.

    import urllib.request,os,hashlib; h = ‘2915d1851351e5ee549c20394736b442’ + ‘8bc59f460fa1548d1514676163dafc88’; pf = ‘Package Control.sublime-package’; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( ‘http://packagecontrol.io/’ + pf.replace(‘ ‘, ‘%20’)).read(); dh = hashlib.sha256(by).hexdigest(); print(‘Error validating download (got %s instead of %s), please try manual install’ % (dh, h)) if dh != h else open(os.path.join( ipp, pf), ‘wb’ ).write(by)

    Ref. Sublime Text Package Control Installation

  3. Restart Sublime Text3

Posted in Sublime Text 3 | Leave a comment

[Java] Write xls files

public String createFile(Object object) {
    try {
        Excel excel = (Excel) object;
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
        for (SheetContent sheetContent:excel.getSheets()) {
            HSSFSheet sheet = hssfWorkbook.createSheet(sheetContent.getName());

            List<HSSFCellStyle> formats = new ArrayList<>();
            /** format */
            for (String format:sheetContent.getFormats()) {
                HSSFCellStyle cs = hssfWorkbook.createCellStyle();
                HSSFDataFormat df = hssfWorkbook.createDataFormat();
                cs.setDataFormat(df.getFormat(format));
                formats.add(cs);
            }

            /** header */
            HSSFRow headerRow = sheet.createRow(0);
            for (int i = 0; i < sheetContent.getHeaders().size(); i++) {
                HSSFCell cell = headerRow.createCell(i);
                cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell.setCellValue(sheetContent.getHeaders().get(i));
            }

            /** content */
            for (int i = 0; i < sheetContent.getRows().size(); i ++) {
                HSSFRow dataRow = sheet.createRow(i + 1);
                for (int j = 0; j < sheetContent.getRows().get(i).getCells().size(); j++) {
                    HSSFCell cell = dataRow.createCell(j);
                    if (StringUtils.isNotEmpty(sheetContent.getFormats().get(j))) {
                        cell.setCellValue(Double.parseDouble(sheetContent.getRows().get(i).getCells().get(j)));
                        cell.setCellStyle(formats.get(j));
                    } else {
                        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(sheetContent.getRows().get(i).getCells().get(j));
                    }
                }
            }

            /** auto size */
            for (int i = 0; i < sheet.getRow(0).getPhysicalNumberOfCells(); i++) {
                sheet.autoSizeColumn(i);
            }
        }

        FileOutputStream out = new FileOutputStream(new File("Excel.xls"));
        hssfWorkbook.write(out);
        out.close();

        return "ok";
    } catch (Exception e) {
        LOG.error(Constants.EXCEPTION_PREFIX, e);
        return null;
    }
}

public class Excel {
    List<SheetContent> sheets;

    public List<SheetContent> getSheets() {
        return sheets;
    }

    public Excel setSheets(List<SheetContent> sheets) {
        this.sheets = sheets;
        return this;
    }

    public Excel addSheets(SheetContent sheet) {
        if (this.sheets == null) {
            this.sheets = new ArrayList<>();
        }
        this.sheets.add(sheet);
        return this;
    }
}

public class SheetContent {
    private String name;
    private List<String> formats;
    private List<String> headers;
    private List<Row> rows;

    public String getName() {
        return name;
    }

    public SheetContent setName(String name) {
        this.name = name;
        return this;
    }


    public List<String> getFormats() {
        return formats;
    }

    public SheetContent setFormats(List<String> formats) {
        this.formats = formats;
        return this;
    }

    public List<String> getHeaders() {
        return headers;
    }

    public SheetContent setHeaders(List<String> headers) {
        this.headers = headers;
        return this;
    }

    public List<Row> getRows() {
        return rows;
    }

    public SheetContent setRows(List<Row> rows) {
        this.rows = rows;
        return this;
    }
}

public class Row {
    private List<String> cells;

    public List<String> getCells() {
        return cells;
    }

    public Row setCells(List<String> cells) {
        this.cells = cells;
        return this;
    }
}
Posted in Excel, Java | Leave a comment