How to create a 3D matrix of values in VB.NET? - matrix

In 2D I write:
Dim matr2D(,) As Integer = { {10, 20, 30}, {11, 21, 31}, {12, 22, 32} }.
In 3D?

Found:
Dim matr3D(, ,) As Integer = { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } }
https://msdn.microsoft.com/it-it/library/2yd9wwz4.aspx

Related

Grepper code extension not showing suggestions and add answer option

As i cleaned up my computer and reinstalled chrome latest version and when i tried using grepper code extension it was not working. It was not showing any answers and not even letting me add a new answer. I tried researching for a while but couldn't find a solution to it.
Then i tried opening it inside the firefox and it was working perfectly and i can even see suggestions and even add new answers.
Then When i checked inside my console log i found some errors while doing a google search and the errors were related to the grepper cross origin issue. I am attaching the screenshot of the issue that occurred
I solved this error by allowing the cross origin access using the following extension :
https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf?hl=en
and then just reloading the page the errors were gone and you can also check if it is working or not inside the test panel of the extension :
https://webbrowsertools.com/test-cors/
I am attaching some screenshots that will define my solution.
/* #api */
define([
'jquery',
'mageUtils'
], function ($, utils) {
'use strict';
var types = [
{
title: 'Visa',
type: 'VI',
pattern: '^4\\d*$',
gaps: [4, 8, 12],
lengths: [16],
code: {
name: 'CVV',
size: 3
}
},
{
title: 'MasterCard',
type: 'MC',
pattern: '^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$',
gaps: [4, 8, 12],
lengths: [16],
code: {
name: 'CVC',
size: 3
}
},
{
title: 'American Express',
type: 'AE',
pattern: '^3([47]\\d*)?$',
isAmex: true,
gaps: [4, 10],
lengths: [15],
code: {
name: 'CID',
size: 4
}
},
{
title: 'Diners',
type: 'DN',
pattern: '^(3(0[0-5]|095|6|[8-9]))\\d*$',
gaps: [4, 10],
lengths: [14, 16, 17, 18, 19],
code: {
name: 'CVV',
size: 3
}
},
{
title: 'Discover',
type: 'DI',
pattern: '^(6011(0|[2-4]|74|7[7-9]|8[6-9]|9)|6(4[4-9]|5))\\d*$',
gaps: [4, 8, 12],
lengths: [16, 17, 18, 19],
code: {
name: 'CID',
size: 3
}
},
{
title: 'JCB',
type: 'JCB',
pattern: '^35(2[8-9]|[3-8])\\d*$',
gaps: [4, 8, 12],
lengths: [16, 17, 18, 19],
code: {
name: 'CVV',
size: 3
}
},
{
title: 'UnionPay',
type: 'UN',
pattern: '^(622(1(2[6-9]|[3-9])|[3-8]|9([[0-1]|2[0-5]))|62[4-6]|628([2-8]))\\d*?$',
gaps: [4, 8, 12],
lengths: [16, 17, 18, 19],
code: {
name: 'CVN',
size: 3
}
},
{
title: 'Maestro International',
type: 'MI',
pattern: '^(5(0|[6-9])|63|67(?!59|6770|6774))\\d*$',
gaps: [4, 8, 12],
lengths: [12, 13, 14, 15, 16, 17, 18, 19],
code: {
name: 'CVC',
size: 3
}
},
{
title: 'Maestro Domestic',
type: 'MD',
pattern: '^6759(?!24|38|40|6[3-9]|70|76)|676770|676774\\d*$',
gaps: [4, 8, 12],
lengths: [12, 13, 14, 15, 16, 17, 18, 19],
code: {
name: 'CVC',
size: 3
}
},
{
title: 'Hipercard',
type: 'HC',
pattern: '^((606282)|(637095)|(637568)|(637599)|(637609)|(637612))\\d*$',
gaps: [4, 8, 12],
lengths: [13, 16],
code: {
name: 'CVC',
size: 3
}
},
{
title: 'Elo',
type: 'ELO',
pattern: '^((509091)|(636368)|(636297)|(504175)|(438935)|(40117[8-9])|(45763[1-2])|' +
'(457393)|(431274)|(50990[0-2])|(5099[7-9][0-9])|(50996[4-9])|(509[1-8][0-9][0-9])|' +
'(5090(0[0-2]|0[4-9]|1[2-9]|[24589][0-9]|3[1-9]|6[0-46-9]|7[0-24-9]))|' +
'(5067(0[0-24-8]|1[0-24-9]|2[014-9]|3[0-379]|4[0-9]|5[0-3]|6[0-5]|7[0-8]))|' +
'(6504(0[5-9]|1[0-9]|2[0-9]|3[0-9]))|' +
'(6504(8[5-9]|9[0-9])|6505(0[0-9]|1[0-9]|2[0-9]|3[0-8]))|' +
'(6505(4[1-9]|5[0-9]|6[0-9]|7[0-9]|8[0-9]|9[0-8]))|' +
'(6507(0[0-9]|1[0-8]))|(65072[0-7])|(6509(0[1-9]|1[0-9]|20))|' +
'(6516(5[2-9]|6[0-9]|7[0-9]))|(6550(0[0-9]|1[0-9]))|' +
'(6550(2[1-9]|3[0-9]|4[0-9]|5[0-8])))\\d*$',
gaps: [4, 8, 12],
lengths: [16],
code: {
name: 'CVC',
size: 3
}
},
{
title: 'Aura',
type: 'AU',
pattern: '^5078\\d*$',
gaps: [4, 8, 12],
lengths: [19],
code: {
name: 'CVC',
size: 3
}
}
];
return {
/**
* #param {*} cardNumber
* #return {Array}
*/
getCardTypes: function (cardNumber) {
var i, value,
result = [];
if (utils.isEmpty(cardNumber)) {
return result;
}
if (cardNumber === '') {
return $.extend(true, {}, types);
}
for (i = 0; i < types.length; i++) {
value = types[i];

GeoShape not storing lat/lng

In ElasticSearch 5 I'm making a property:
var prop = new Property
{
Id = page.Id,
GeoLocation =
new PointGeoShape(
new GeoCoordinate((double) geoPoint.Latitude, (double) geoPoint.Longitude))
};
With a definition of:
public class Property
{
[Number]
public int Id { get; set; }
[GeoShape]
public PointGeoShape GeoLocation { get; set; }
}
When it's being sent to elastic it's got a type of point, and the lat and lng are both doubles.
However when it inserts into elastic and I get it back it looks like:
"GeoLocation": {
"coordinates": [
{
"s": -1,
"e": -2,
"c": [
7,
9,
0,
2,
8,
9,
9,
0,
2,
1,
3,
0,
3,
2,
5,
5,
7
]
},
{
"s": 1,
"e": 1,
"c": [
5,
1,
5,
2,
6,
5,
2,
0,
3,
7,
4,
7,
1,
9,
8,
3
]
}
],
"type": "point"
This was due to postman 'prettify', when I checked the raw response it was correct.

How to allow Duplicate Tick Labels in Plotly?

I observed that while providing duplicate ticklabels (with an aim to mention the class of categorical variable), plotly creates a unique set and displays only the non-repeated tick labels. Is there a way to by-pass this feature and allow duplicate tick-labels?
var data = [
{
z: [[1, 20, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]],
x: ['Healthy', 'Healthy', 'Moderate', 'Diseased', 'Diseased'],
y: ['Morning', 'Afternoon', 'Evening'],
type: 'heatmap'
}
];
Plotly.newPlot('myDiv', data);
Following is the jsfiddle depicting the issue:
https://jsfiddle.net/mam8sgwx/
Set the layout with ticktext:
var layout = {
xaxis: {
tickmode: "array",
ticktext: ['Healthy', 'Healthy', 'Moderate', 'Diseased', 'Diseased'],
tickvals: [0, 1, 2, 3, 4]
}
}
Here is the demo:
var data = [{
z: [
[1, 20, 30, 50, 1],
[20, 1, 60, 80, 30],
[30, 60, 1, -10, 20]
],
y: ['Morning', 'Afternoon', 'Evening'],
type: 'heatmap'
}];
var layout = {
xaxis: {
tickmode: "array",
ticktext: ['Healthy', 'Healthy', 'Moderate', 'Diseased', 'Diseased'],
tickvals: [0, 1, 2, 3, 4]
}
}
Plotly.newPlot('myDiv', data, layout);
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<body>
<div id="myDiv"></div>

Datatable scroll x issue using fixedColumn

im using jquery datatables with fixedColumns. Everything working fine but im having an issue with scroll x.
As u can see, i cant remove the scroll x from fixed column. Any ideas to solve this? Initialization:
$(document).ready(function(){
var oTable = $('#matriz').dataTable({
"bStateSave": true,
"iCookieDuration": 60*60*24*30*365,
"sDom": 'TC<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "//cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "xls",
"sButtonText": "Excel",
"mColumns":
[
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22
]
}
]
},
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets':
[
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23
]
}
],
"pagingType": "full_numbers",
"oLanguage": {
"sInfo": "Exibindo de _START_ até _END_. Resultados encontrados: _TOTAL_",
"sSearch": "Pesquisar: ",
"sEmptyTable": "Não existem solicitações para exibir.",
"sLengthMenu": "Visualizar _MENU_ solicitações",
"oPaginate": {
"sFirst": "Primeira",
"sLast": "Última",
"sNext": "Próxima",
"sPrevious": "Anterior"
}
},
"oColVis": {
"buttonText": "Ocultar colunas",
"bRestore": true,
"aiExclude": [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 23 ],
"sRestore": 'Restaurar'
},
"lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "Todas"]],
"iDisplayLength": 10,
scrollY: 325,
"sScrollX": "100%",
scrollCollapse: true,
fixedColumns: {
leftColumns: 1
}
});
setTimeout(function (){
oTable.fnAdjustColumnSizing();
}, 10 );
});
Adding overflow-x:hidden to the DTFC_LeftBodyLiner div seems to fix the display issue.

Merging and updating hash keys in Redis with Ruby

I have a list the following hashes:
{
key_main1: {
k1: 1,
k2: 11,
k3: 33,
k4: 146,
k5: 12,
# etc
},
key_main2: {
k1: 1,
k2: 11,
k3: 33,
k4: 146,
k5: 12,
# etc
},
# etc
}
which is save in a redis as json:
redis_key1 = "redis_key1"
redis.set("redis_key", my_hash.to_json)
redis.get("redis_key") # =>
"{"key_main":{"k1":1,"k2":11,"k3":33,"k4":146,"k5":12}}"
The hashes have the same structure but can have different keys. On each iteration I want to update the existing keys by summing up the values of "k"s or/and insert the keys that don't exist:
So the second hash in the list looks like this
{
key_main1: {
k3: 44,
k4: 14,
k18: 99
},
key_main3: {
k2: 77
}
}
Then after the seconds iteration the result in Redis will look like the following:
{
key_main1: {
k1: 1,
k2: 11,
k3: 33,
k4: 160,
k5: 12,
k18: 99
},
key_main2: {
k1: 1,
k2: 11,
k3: 33,
k4: 146,
k5: 12
},
key_main3: {
k2: 77
}
}
What's the easiest and best way to do it? Do I have to parse (restore)json in each iteration in order to check if the keys exist and update or insert them?
The best way is to parse the JSON back into a hash, otherwise you will have a really hard time figuring out how to combine the hashes.
To combine them, the best and easiest is with Hash#merge:
h1 = { m1: { k1: 10, k2: 20, k3: 30 }, m2: { k1: 11, k2: 12 } }
h2 = { m1: { k1: 500, k2: 5, k4: 40 }, m3: { k2: 123 } }
pp h1.merge(h2) { |key, v1, v2|
v1.merge(v2) { |key, v1, v2| v1 + v2 }
}
=> { :m1 => { :k1 => 510,:k2 => 25, :k3 => 30, :k4 => 40 },
:m2 => { :k1 => 11, :k2 => 12},
:m3 => { :k2 => 123 } }
This code assumes the keys in h1 and h2 always contain a hash with integer keys.

Resources