Roy Tang

roytang.net

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

Subscribe: RSS JSON

2019 January

  • I still Google the most basic things

    I've been working with Javascript for more than a decade. Last week while helping another developer debug a problem, I had to Google how to check if an element exists in a Javascript array, something superbasic, that one would expect most newbies to know. I'm sure I Google some superbasic thing at least once a week. It's not embarassing or anything, it's a common occurrence. I'm surely not alone. Just last night a tweet about this crossed my TL: In C++ we don't say "Missing asterisk" we say "error C2664: 'void std::vector<block,std::allocator<_Ty>>::push_back(const block &)': cannot convert argument 1 from 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<block>>>'

    read more (339 words)

2017 December

  • How to specify that a column in the schema should be nullable?

    I tried adding a nullable attribute:

    var myFirstTDE = xdmp.toJSON(
      {
        "template": {
          "context": "/match",
          "collections": ["source1"],
          "rows": [
            {
              "schemaName": "soccer",
              "viewName": "matches",
              "columns": [
                {
                  "name": "id",
                  "scalarType": "long",
                  "val": "id",
                  "nullable": 0
                },
                {
                  "name": "document",
                  "scalarType": "string",
                  "val": "docUri"
                },
                {
                  "name": "date",
                  "scalarType": "date",
                  "val": "match-date"
                },
                {
                  "name": "league",
                  "scalarType": "string",
                  "val": "league"
                }
              ]
            }
          ]
        }
      }
    );
    
    tde.validate( 
      [myFirstTDE]
    );
    

    But this gave me a template error:

    "message": "TDE-INVALIDTEMPLATENODE: Invalid extraction template node: fn:doc('')/template/array-node('rows')/object-node()/array-node('columns')/object-node()[1]/number-node('nullable')"
    

    For a template defined using XQuery, adding nullable to the column works:

    <column>
      <name>ISSN</name>
      <scalar-type>string</scalar-type>
      <val>Journal/ISSN</val>
      <nullable>true</nullable>
    </column>
    

    How to do the same thing using JS/Json?

2017 November

2017 October

2017 September

2017 July

2017 June

2016 December

  • In JavaScript, referencing variables that are declared outside of a function's scope can be tricky. If you have code like this: var btn = document.getElementById("BTN"); var test = 1; btn.onclick = function() { alert(test); } test = 2; The click handler above retains a reference to the test variable even though it falls out of scope as soon as the script block finishes execution. When you actually click the button, the alert will show the last value of the variable when the block finished execution (2) instead of the value at the time the function was initialized (1). I thought

    read more (361 words)

2014 February

2013 March

2012 July

2011 December

2010 December

2010 September

2010 August

2010 July