zaterdag 30 maart 2019

Postgresql json datatype

https://stackoverflow.com/questions/36141388/how-can-i-get-all-keys-from-a-json-column-in-postgres

select jt.*
from (select key as key, value as valuestr, count(*) over () as metadata_aantal from json_each_text('{"Key1":"Value1", "Key2":"Value2"}'::json)) jt

https://www.postgresql.org/docs/11/functions-json.html

select * from table t where t.jsonbcolumn->'nummer' = '22420';

select id from aTable where last_message->'Gegevens'->>'prio' = '1' order by id

jsonb veld aanpassen:
SELECT '{"a":1}'::jsonb || '{"b": 1}'::jsonb;

https://stackoverflow.com/questions/18209625/how-do-i-modify-fields-inside-the-new-postgresql-json-datatype

update table set data = '{"Key1": true, "Key2": "yoho"}'::jsonb where id = 'theid001';

donderdag 7 maart 2019

C# HttpClient https without certificate

var spHandler = new HttpClientHandler()
{
      ServerCertificateCustomValidationCallback = delegate
      {
          return true;
      }
};
var hc = new System.Net.Http.HttpClient(spHandler);
var response = await hc.GetAsync("https://adress");

zondag 6 januari 2019

vrijdag 4 januari 2019

Upload folder with .NET Core and JQuery

Client (javascript) :
let uploadInput = $('<input type="file" id="file" name="file" size="10" accept="image/*" webkitdirectory mozdirectory />');

        function uploadButtonClick() {
            let promiseArray = [];
            let theFiles = $('#file')[0].files;
            for (let i = 0; i < theFiles.length; i++) {
                let aFile = theFiles[i];
                (function (theFile) {
                    promiseArray.push(uploadFile(theFile));
                })(aFile);
            }
            $.when.apply($, promiseArray).then(function () {
            });
        }

        function uploadFile(theFile) {
            let deferred = $.Deferred();
            var formData = new FormData();
            formData.append('parameter1', 'value1');
            formData.append('file', theFile, theFile.webkitRelativePath);
            $.ajax({
                method: "POST",
                url: '/v1/UploadFile',
                data: formData,
                cache: false,
                contentType: false,
                processData: false
            }).done(function (response) {
                deferred.resolve(response);
            });
            return deferred.promise();
        }

Server (.NET Core controller):

        [HttpPost]
        [RequestFormLimits(MultipartBodyLengthLimit =209715200)]
        [RequestSizeLimit(209715200)]
        [Route("UploadFile")]
        public ActionResult<List<string>> UploadFile(IFormFile file, [FromServices] IHostingEnvironment env)
        {
            string uploadDir = "c:\\dir\\upload";
            string dirPart = Path.GetDirectoryName(file.FileName);
            Directory.CreateDirectory(uploadDir + "\\" + dirPart);

            string fileNamePart = file.FileName; // Path.GetFileName(file.FileName);
            string fileName = $"{uploadDir}\\{fileNamePart}";
            using (FileStream fs = System.IO.File.Create(fileName))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            var result = new List<string>();
            result.Add($"{file.Length} bytes uploaded successfully.");
            return result;
        }

dinsdag 1 januari 2019

Organisatie moet zelf ook scalable en non-blocking zijn, net als de software die het gebruikt.

Wil je een gedistribueerd, scalable, asynchroon, non-blocking software gebruiken, dan moet je organisatie ook zo werken, anders gaat het geen rendement geven.
Dus geen dead-locks, zoals grote meetings en conference calls waarin iedereen veel tijd kwijt is.
Inspiratie van Pieter Hintjens van ZeroMQ uit: https://www.youtube.com/watch?v=yhGXJ9Jt3-A