All posts by stackoverflow

R reshape matrix by rows

I have a matrix with size 18000 x 54. I would like to reshape it as a matrix with size 54000 x 18, in which each row of my initial matrix becomes a matrix which has 3 rows.

read more

How to get the Text value of Anchor tag inside this li class

Sorry for the noob question, I’m still learning in Javascript. I just want to get the “Welcome” text when the page load and save it to a variable so I could make a string compare.

<nav id="top-menu-nav">
    <ul id="top-menu" class="nav">
        <li id="menu-item-103" class="menu-item">
            <a href="#">About Us</a>
        </li>
        <li id="menu-item-25417" class="menu-item">
            <a href="#">Offers</a>
        </li>
        <li id="menu-item-102" class="menu-item">
            <a href="#">FAQ</a></li>
        <li id="menu-item-104" class="menu-item">
            <a href="#">Corporate</a></li>
        <li id="menu-item-100" class="menu-item">
            <a href="#">Contact Us</a></li>
        <li class="login">
            <a href="#">Welcome</a>
        </li>
    </ul>
</nav>

read more

sqlCommand does not contain a definition for Parameters

Error 1 ‘vijaystore.DAL.sqlCommand’ does not contain a definition for
‘Parameters’ and no extension method ‘Parameters’ accepting a first
argument of type ‘vijaystore.DAL.sqlCommand’ could be found (are you
missing a using directive or an assembly
reference?) E:\VIJAY\vijaystore\vijaystore\DAL\userDAL.cs 69 21 vijaystore

try
{
    String sql = "INSERT INTO tbl_user (first_name, last_name, email, username, password, contact, address, gender, user_type, added_date, added_by) VALUES (@first_name, @last_name, @email, @username, @password, @contact, @address, @gender, @user_type, @added_date, @added_by)";
    sqlCommand cmd = new sqlCommand(sql, conn);

    cmd.Parameters.AddwithValue("@first_name", u.first_name);
    cmd.Parameters.AddwithValue("@last_name", u.last_name);
    cmd.Parameters.AddwithValue("@email", u.email);
    cmd.Parameters.AddwithValue("@username", u.username);
    cmd.Parameters.AddwithValue("@password", u.password);
    cmd.Parameters.AddwithValue("@contact", u.contact);
    cmd.Parameters.AddwithValue("@address", u.address);
    cmd.Parameters.AddwithValue("@gender", u.gender);
    cmd.Parameters.AddwithValue("@user_type", u.user_type);
    cmd.Parameters.AddwithValue("@added_date", u.added_date);
    cmd.Parameters.AddwithValue("@added_by", u.added_by);

read more

Angular 8 Lazy Loading Syntax Not Working

I’m trying to implement Lazy loading into my Angular 8 application but when I use the syntax provided in the official doc, my module gets loaded eagerly.

When I use the syntax that comes with angular 8:

const routes: Routes = [{
  path: 'lazy',
  // The new import() syntax
  loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule)
}];

I get no error but I don’t get a new chunk when I build the app, and when navigationg to the module route, nothing appears in the Network tab of chrome. (Although I can navigate to the module just fine)

But if I rewrite it to:

const routes: Routes = [{
  path: 'lazy',
  // The following string syntax for loadChildren is deprecated
  loadChildren: './lazy/lazy.module#LazyModule'
}];

(which is the old syntax)
it works fine.

The module in question is definitely not imported anywhere else, the difference in result comes only from changing the syntax.

I’d like to know if there is something I’m missing there. I’m thinking maybe it’s my Angular that isn’t correctly set up to version 8 (or some other package)
So here’s what I have with a ng version:

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.4
@angular-devkit/build-angular     0.800.4
@angular-devkit/build-optimizer   0.800.4
@angular-devkit/build-webpack     0.800.4
@angular-devkit/core              8.0.4
@angular-devkit/schematics        8.0.4
@angular/cdk                      8.0.0
@angular/cli                      8.0.4
@angular/material                 8.0.0
@ngtools/webpack                  8.0.4
@schematics/angular               8.0.4
@schematics/update                0.800.4
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

read more

How to make values show up in input boxes

This is my first time coding, and I’m trying to create a feature on my website where after I select an item from the dropdown menu, values corresponding to that item will show up in the input boxes I created. An example is if I select “apples” from my dropdown menu, the values “1.2” and “4.00” will show up in the “Pounds” and “Cost” input boxes respectively.

I already have code written using HTML and JS for the dropdown menu and input boxes, and I have stored the data corresponding to the items in a csv file. Right now, values show up in the input boxes only because I wrote code for that in JS. Is there any way for the HTML file to read my data from a csv file and display that data in my input boxes? Below is what I have so far.

<div id="cs-element">
  <label id="cs-element-label">Elements</label>
</div>

<select onChange="dropdownTip(this.value)" name="search_type" style="margin-right:10px; margin-top:2px;">
 <option selected="selected">Choose Element</option>
 <option>Methane</option>
 <option>Ethane</option>
 <option>Propane</option>
 <option>n-Butane</option>
</select>

<div id="result"></div>

<script type="text/javascript">
 function dropdownTip(value){
   console.log(value);
    document.getElementById("myText").value="190.6";
    document.getElementById("myText1").value="45.99";
    document.getElementById("myText2").value="0.012";
 }
</script>

<div id="cs-tc" class="col-sm-4 text-center">
  <label id="cs-tc-label" class="control-label">Critical Temperature (K)</label>
 <input type="text" id="myText" value=" " class="form-control" name="cs_tc">
</div>

<div id="cs-pc" class="col-sm-4 text-center">
  <label id="cs-pc-label" class="control-label">Critical Pressure (atm)</label>
  <input type="text" id="myText1" value=" " class="form-control" name="cs_pc">
</div>

<div id="cs-acc" class="col-sm-4 text-center">
  <label id="cs-acc-label" class="control-label">Accentric Factor</label>
  <input type="text" id="myText2" value=" " class="form-control" name="cs_acc">
</div>

<script>
$(document).ready(function() {
  $.ajax({
    type: "GET",
    url: "B1_1.csv", //read csv file
    dataType: "text",
    success: function(data) {processData(data);}
   });
});

function processData(allText) {
 var allTextLines = allText.split("/\r\n|\n/");
 var headers = allTextLines[0].split(',');
 var lines = [];

 for (var i=1; i<allTextLines.length; i++) {
  var data = allTextLines[i].split(',');
  if (data.length == headers.length) {

   var tarr = [];
   for (var j=0; j<headers.length; j++) {
    tarr.push(headers[j]+":"+data[j]);
   }
   lines.push(tarr);
  }
 }
}
</script>

read more