George Opritescu

Developer from somewhere

java deserialization with jackson

Been debugging a deserialization issue for 3 hours. Turns out I had this in my code:

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonSetter;

When, it should have been these:

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Read More

javascript format currency with intl

Problem:

Solution:

  • step 1
// some code here
Read More

hbase scan example

Problem: want to perform a scan on a table, and list the values.

Solution:

        Scan scan = new Scan();
        ResultScanner scanner = someTable.getScanner(scan);

        for(Result row : scanner) {

            List<Cell> cells = row.listCells();

            for(Cell c : cells) {
                byte columnFamily[] = CellUtil.cloneFamily(c);
                byte qualifier[] = CellUtil.cloneQualifier(c);
                byte value[] = CellUtil.cloneValue(c);
                System.out.println("columnFamily:" + Bytes.toString(columnFamily) +
                    " qualifier:" + Bytes.toString(qualifier) + " value:" + Bytes.toString(value));
            }
        }
Read More

java hbase obtain column families for a particular table

Problem: want to obtain column families for a particular table.

Solution:

        Connection conn = ConnectionFactory.createConnection(config);
        Admin admin = conn.getAdmin();

        TableName transactionTableName = TableName.valueOf("some_table");
        HTableDescriptor tableDesc = admin.getTableDescriptor(transactionTableName);
        // this will contain all of them
        HColumnDescriptor colDesc[] = tableDesc.getColumnFamilies();
Read More

git merge unrelated histories

Problem: want to merge 2 branches that don’t share a common history.

Solution:

git merge --allow-unrelated-histories somebranch
Read More
git

view principals in a kerberos keytab file

Problem: want to see principals in a keytab file.

Solution:

  • start ktutil
ktutil
  • read your keytab file:
ktutil:  read_kt /path/to/some.keytab
  • list them:
ktutil: list
Read More

centos install epel

Problem: need epel to install extra packages.

Solution:

sudo yum install epel-release
Read More

javascript map async await

Problem: want to obtain the text from an array of elements

Solution:

  • Promise.all and async await map:
const childrenTable = await driver.findElement(By.css('table'))
const childrenEntries = await childrenTable.findElements(By.css('tr'))
const childrenText = await Promise.all(childrenEntries.map(async (cd) => cd.getText()))
Read More

selenium webdriver chrome headless

Problem: wanted to use chrome headless in selenium tests.

Solution: found here. Since I’m using chrome 61, I don’t need to set the binary to chrome.

    const options = new chromeDriver.Options()
    options.addArguments(
        'headless',
        // Use --disable-gpu to avoid an error from a missing Mesa library, as per
        // https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
        'disable-gpu',
    )
    const browser = new webdriver.Builder()
        .forBrowser(targetBrowser)
        .setChromeOptions(options)
        .build();
    // ... do your thing here    
Read More

create-react-app environment variables

Problem: wanted to pass environment variables to an app created with create-react-app ( in development )

This is how I did it ( not exactly sure which version of react-scripts I’m using, since I ejected the config ):

  • create a .env.development file, in your app’s root folder and add your variables there:
API_URL=http://api.local
  • open config/envs.js and add your variable to the object in getClientEnvironment function:
      {
        // Useful for determining whether we’re running in production mode.
        // Most importantly, it switches React into the correct mode.
        NODE_ENV: process.env.NODE_ENV || 'development',
        // Useful for resolving the correct path to static assets in `public`.
        // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
        // This should only be used as an escape hatch. Normally you would put
        // images into the `src` and `import` them in code to get their paths.
        PUBLIC_URL: publicUrl,
        API_URL: process.env.API_URL,
      }
Read More