Stacks

 

Whenever i get time from my work or personal life I try to solve the questions posted in Stacksoverflow. It help me to keep update every time. As there are big brains out their who implement new things or do the same thing in some interesting ways.  And also I can recall and share few implementation of my self answering related questions.

And YES….I do also ask question whenever i done with enough googling. The best thing in stack is it will provide correct answer within few minutes and only correct answers are promoted by the users.

My account link : Suresh Kamrushi
Listing below some of the questions and answer in which i have participated.

User Suresh Kamrushi - Stack Overflow

most recent 30 from stackoverflow.com

for me even it is not working in firefox built in tools (ctrl+shift+k)
Author: Suresh Kamrushi
Posted: January 17, 2018, 8:45 am
A detailed blog: sforsuresh.in/…
Author: Suresh Kamrushi
Posted: January 9, 2018, 10:56 am
A detailed blog: sforsuresh.in/…
Author: Suresh Kamrushi
Posted: January 9, 2018, 10:56 am
A detailed blog :sforsuresh.in/…
Author: Suresh Kamrushi
Posted: January 9, 2018, 10:55 am
Author: Suresh Kamrushi
Posted: January 9, 2018, 10:42 am
what error you are getting?
Author: Suresh Kamrushi
Posted: January 5, 2018, 5:53 am
my bad. Its working. Thanks for your help
Author: Suresh Kamrushi
Posted: December 28, 2017, 10:36 am
getting error " Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator '==' cannot be applied to operands of type 'string' and 'int'"
Author: Suresh Kamrushi
Posted: December 28, 2017, 10:21 am

It might be silly to ask but still i am not able to google it correctly. Below is my code to print "selected" in view:

<option value="0" @if(ViewBag.country == 0)  { @:selected } >NO</option>

it is giving me error like

Parser Error Message: The if block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

Referred :https://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/

Author: Suresh Kamrushi
Posted: December 28, 2017, 9:53 am

I am able to get like this:

System.Configuration.ConfigurationManager.AppSettings.Get("KEY").ToString();
Author: Suresh Kamrushi
Posted: December 6, 2017, 8:43 am

You can run both server simultenously by changing port number of Apache or IIS.
A) How you can change Apache port number:

1) Open “httpd.conf” file located in folder “C:\wamp64\bin\apache\apache2.4.23\conf”. You can also open file directly from system try if your wamp is running.
2) Search for “listen” text in file and update the default port 80 to 8080.
3) Now Restart the WAMP server to make new port number effective.
4) Open the browser with url “http://localhost:8080/” wamp will show home page.
Reff: http://sforsuresh.in/iis-and-wamp-servers-on-the-same-system/

B) How you can change IIS port:
1) Go start and type IIS.
2) IIS Manager will open. click on “Default Web Site” on left hand side.
3) click on “bindings…” from the right side action section.
4) Popup will open with 80 port listed. select it and click the edit button.
5) Update the port and restart the server.Now try to access using browser.

Reff: http://sforsuresh.in/change-iis-port-windows/

Author: Suresh Kamrushi
Posted: November 24, 2017, 6:28 am

you can do something like below:

$oldtime = "20:30pm - 23:30pm";
$newtime = explode(" - ", $oldtime);
foreach($newtime as $k => $t) {
$time[$k] = DateTime::createFromFormat('H:iA', $t);
echo $time[$k]->format('H:i:s');  //or any other format you want
}

You can get more info : http://php.net/manual/en/datetime.createfromformat.php

Author: Suresh Kamrushi
Posted: November 23, 2017, 9:26 am

Set value as :

<option class="form-control" value="{{$play->id}}**{{$play->unit}}" >{{$play->attribute}}</option>

You will get both values after submit. You need to explode() like:

$attribute = $_POST['attribute'];
$values = explode("**", $attribute);
echo $values[0];  //will contain id
echo $values[1];  // will contain unit

I am using "**" as a separator, you can use anything.

Author: Suresh Kamrushi
Posted: November 23, 2017, 6:05 am

You can use event scheduler to perform the task like below:

DELIMITER //
CREATE EVENT eventName
ON SCHEDULE EVERY 1 WEEK
STARTS 'Some Date to start'
ENDS 'End date If any' 

DO
BEGIN
   DELETE FROM NeoTec_test WHERE NOW() > Expiry
END//
DELIMITER ;
Author: Suresh Kamrushi
Posted: November 16, 2017, 6:34 am

You can do like this:

$( "button" ).click(function() {
  $( this ).attr("id");
});

Or alternatively you can also use prop() method:

$( "button" ).click(function() {
  $( this ).prop("id");
});

for documentation you can reff:
https://api.jquery.com/attr/
https://api.jquery.com/prop/

Author: Suresh Kamrushi
Posted: November 16, 2017, 6:28 am

enter image description hereIf you are using phpmyadmin do the following steps:
1) select the database
2) Select search from the top links
3) Now you will get text box to enter what to search
4) Select the table in which you want to search. It will search whole database get the result

Author: Suresh Kamrushi
Posted: November 16, 2017, 5:54 am

For this issue you can try either of below solutions:
1) It is permission issue with android 6. So to fix the issue configure platform to android 5.0.

OR if you are using MI note 4 you can try below additional steps:

There is another permission required in MIUI secruity system and after enabling it, camera started working.
Following are the steps you can follow to update the setting:
1) Go to Security.
2) Click on “Permissions” and again select “Permissions”
3) Now from the list, click on “Camera”.
4) It will list all the apps installed. Look for your app and enable the permission.

Reff: http://sforsuresh.in/cordova-sorry-android-camera-encountered-problem/

Author: Suresh Kamrushi
Posted: November 8, 2017, 6:20 am

In MIUI 8.5 it gives the error like you mention while enabling "install via USB", to resolve the error you need to make WIFI off and make mobile data on and then enable the option “Install via USB”. it will work for you.

A detailed blog: http://sforsuresh.in/xiaomi-mi-note-4-install-via-usb-device-temporarily-restricted/

Author: Suresh Kamrushi
Posted: October 18, 2017, 8:20 am

Now in updated MIUI 8 in Xaomi Redmi Note 4, "Install via USB" is moved to "developer option". So go to setting => additional Settings => Developer Options => update "Install via USB".

Few more details in blog: click here

Author: Suresh Kamrushi
Posted: October 13, 2017, 12:41 pm

Better you can do like this:

$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}

Code copied from :http://php.net/manual/en/function.fgetcsv.php
alternatively : http://php.net/manual/en/function.str-getcsv.php

Author: Suresh Kamrushi
Posted: September 26, 2017, 10:11 am

You can update "urlAddLocalhost" variable in "wamp64/wampmanager.conf" file to on/off. By default it is "off".
My wamp version is 3.0.6.

urlAddLocalhost = "off" 

enter image description here

Author: Suresh Kamrushi
Posted: September 21, 2017, 8:36 am

Getting error as "npm ERR! errno -4058". and at the end it showing like "Please include the following file with any support request:" whatever solution i got from google and stacks is not working out for me. Any help appreciated.

ant -f C:\\wamp64\\www\\mobileApp\\cordova\\HTML5Application\\nbproject "-Dupdate.task.jar=C:\\Program Files\\NetBeans 8.2\\webcommon\\ant\\extra\\org-netbeans-modules-cordova-projectupdate.jar" -Dandroid.project.activity=HTML5Application -Dsite.root=www -Dstart.file=index.html -Dandroid.sdk.home=E:\\Suresh\\Projects\\BillonDeal\\adt-bundle-windows-x86_64-20140702\\sdk -Dandroid.target.device.arg=run -Dcordova.version=7.0.1-0.0.0 -Denv.DISPLAY=:0.0 "-Dios.certificate.name=iPhone Developer" -Dandroid.build.target=android-16 -Dconfig=android_1 sim-android
check-android-template:
check-cordova-version:
check-cordova-project:
upgrade-to-cordova-project:
create-android:
update-plugins:
cordova.cmd plugins 
cordova.cmd -d plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git
No scripts found for hook "before_plugin_add".
Calling plugman.fetch on plugin "https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git"
saving
Running command: cmd "/s /c ""C:\Program Files\nodejs\npm.cmd" install https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git --save""
Command finished with error code 4294963238: cmd /s /c ""C:\Program Files\nodejs\npm.cmd" install https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git --save"
Error: Failed to fetch plugin https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: cmd: Command failed with exit code 4294963238 Error output:
npm ERR! not a package C:\Users\ADMINI~1\AppData\Local\Temp\npm-1476-73df7ab4\git-wip-us.apache.org\repos\asf\cordova-plugin-dialogs.git
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git" "--save"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! path C:\Users\ADMINI~1\AppData\Local\Temp\npm-1476-73df7ab4\unpack-d65611f4\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\ADMINI~1\AppData\Local\Temp\npm-1476-73df7ab4\unpack-d65611f4\package.json'
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\ADMINI~1\AppData\Local\Temp\npm-1476-73df7ab4\unpack-d65611f4\package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     C:\wamp64\www\mobileApp\cordova\HTML5Application\node_modules\npm-debug.log
C:\wamp64\www\mobileApp\cordova\HTML5Application\nbproject\build.xml:235: exec returned: 1
BUILD FAILED (total time: 9 seconds)
Author: Suresh Kamrushi
Posted: September 20, 2017, 9:28 am

You can try something like this:

$date = DateTime::createFromFormat('YmdHis', '20170912131313');
$date->add(new DateInterval('P10D'));
echo $date->format('Y-m-d');

For more information: http://php.net/manual/en/datetime.add.php

Author: Suresh Kamrushi
Posted: September 12, 2017, 8:12 am

The error tells that you did not loaded to Database. You can load your database in contorller like:

$this->load->database();

Or in autoload.php like below:

$autoload['libraries'] = array('database');
Author: Suresh Kamrushi
Posted: July 17, 2017, 5:31 am

Whatever i understand from your question you can look like below:

if ($stmt2->rowCount() > 0) {
    while ($row = $stmt2->fetch(PDO::FETCH_ASSOC)) {
?>
<tr>
<td><input type = "text" name = "finanIns1" id = "finanIns1" value = "<?php $row['columnName']?>" readonly></td>
<td>
<input list = "proTypeList" name = "proType1" id = "proType1"readonly >

</td>
<td id = "balance"><input type = "number" name = "balance1" id = "balance1" value = "<?php $row['columnName']?>" min = "0"readonly></td>
<td id = "MonthyComm"><input type = "number" name = "monthlyComm1" id = "monthlyComm1" value = "" min = "0"readonly></td>

</tr>

<tr>
<td><input type = "text" name = "finanIns2" id = "finanIns2" value = "<?php $row['columnName']?>" readonly></td>
<td>
<input list = "proTypeList" name = "proType2" id = "proType2" readonly>

</td>
<td id = "balance"><input type = "number" name = "balance2" id = "balance2" value = "<?php $row['columnName']?>" min = "0"readonly></td>
<td id = "MonthyComm"><input type = "number" name = "monthlyComm2" id = "monthlyComm2" value = "<?php $row['columnName']?>" min = "0"readonly></td>

</tr>
<?php


        ?>
        <?php
    }
Author: Suresh Kamrushi
Posted: July 11, 2017, 6:05 am

You can do something like below:

$query = "SELECT json_object('image_name', image_name, 'iid', iid) FROM `posts_images` WHERE `pid` = '62'";
$result = mysqli_query($query);
$data = array();
while($row = mysqli_fetch_assoc($result)) {
    $data[] = $row;
}
print json_encode($data);
Author: Suresh Kamrushi
Posted: July 5, 2017, 11:42 am

You need to get the profile pic from table and show it on profile. You can do something like below (as i am not sure what and where you are missing the logic) In controller you can write like below:

$data['profilePic'] = $this->db->query("Your query to user table")->row()->profiel_foto;
$this->load->view('view file', $data);

And in View

<img src="<?php echo base_url(); ?>upload/<?php echo $profilePic?>">

I am assuming you are storing image name in table with column 'profiel_foto'.

Author: Suresh Kamrushi
Posted: June 30, 2017, 9:26 am

You can do like this:

SELECT id, CONCAT(dateval,' ',hourval,':',minval,':00') as t 
 FROM ForgeRock 
 WHERE CAST(CONCAT(dateval,' ',hourval,':',minval,':00') as DATETIME) 
  between CAST('2006-01-21 17:10:00' as DATETIME) AND 
   CAST('2006-01-25 22:10:00' as DATETIME) 

Because of concate() we need to use CAST to convert them as datetime. SQL fiddle for it: http://sqlfiddle.com/#!9/4a072/12

Author: Suresh Kamrushi
Posted: June 30, 2017, 8:52 am

You can use glob() function something like below:

<?php
   $findThisString = stripcslashes($_POST["recherchemotcle"]);
   $path = "tuto";
   $list =glob($path."/".$findThisString."*.*"); 
   foreach ($list as $l) {          
         $files[] = $l;
   }
?> 
Author: Suresh Kamrushi
Posted: June 21, 2017, 10:43 am

I think you should write like this:

$( "#device-selection" ).change(function() {
    console.log($('#device-selection').data('width'));
    console.log($('#device-selection').data('height'));
});

Jquery documentation: https://api.jquery.com/change/

Check W3shool example :https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_change_ref

Author: Suresh Kamrushi
Posted: June 21, 2017, 10:25 am

You can do like this:

<div class="pretpark-container">
    <table id="pretpark-table">
      <?php while($pretpark = mysqli_fetch_array($result)){ 
      echo "<tr>";
      if(file_exists(__DIR__ . '/img/'. $pretpark['ParkImage'])): ?>
      <td><img height="125px;" width="200px;"" src="/WikiParksWeb/Wikiparks-Website/img/<?php print($pretpark['ParkImage']); ?>"></td>
      <?php else: ?>
      <?php endif; 
      echo "<td>".$pretpark['ParkName']."</td>";
      echo "<td>".$pretpark['ParkLocation']."</td>";
      echo "<td>".$pretpark['ParkOpeninsTime']."</td>";
      echo "<td>".$pretpark['ParkPrices']."</td>";
      echo "<td>".$pretpark['ParkShortDescription']."</td>";
      echo "<td><a href='example.php?park=".$pretpark['Parkid']."'> More Details</a></td>";
      echo "</tr>"; 
      ?> 
      <tr class="filler"></tr> 
      <?php
      }
      ?>       
    </table>     
  </div>
Author: Suresh Kamrushi
Posted: June 20, 2017, 11:27 am

How to increase the size of the Clipboard:

  1. Click the Start button. Type sysdm.cpl into the search box and press the Enter key.
  2. Click the Advanced tab in the System Properties window. Click the Settings button under the Performance label header.
  3. Click the Advanced tab in the Performance Options window. Under the Virtual Memory header, click the Change... button.
  4. Clear the check box next to the Automatically manage paging file size for all drives option. This disables automatic "Virtual Memory" settings in Windows.
  5. Enter a value for the size of the new paging file. Enter a value larger than the current paging file size in the "Maximum Size" field (enter the value in megabytes). Click the Set button and then OK.
  6. Restart the computer for the new "Virtual Memory" settings to take effect. The Windows Clipboard now stores more data when copying and pasting between applications.

Reference: I need to increase the clip board size in Word

A detailed blog with screenshots :http://sforsuresh.in/increase-size-clipboard-of-windows-10-7/

Author: Suresh Kamrushi
Posted: January 8, 2014, 6:55 am

How can I increase the size of the clipboard in Windows 7?

While copying large amounts of data, I get the following error:

Item to large for Clipboard.

Author: Suresh Kamrushi
Posted: December 31, 2013, 9:31 am

I have two tables as below: User table:

CREATE TABLE `user` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
    PRIMARY KEY (`id`)      
);

And another table as uep which as below:

CREATE TABLE `uep` (
  `user_id` int(10) unsigned NOT NULL,
  `email_template_id` int(10) unsigned NOT NULL,
  `sid` int(10) unsigned NOT NULL,
  `send_email` tinyint(1) NOT NULL DEFAULT '1'
);

I want to get all records from user table and do left join to uep table only when
user.id = uep.user_id AND uep.send_email = 0

but when i run query

Select id, group_concat(email_template_id) as T from user
LEFT join uep ON (user.id = uep.user_id AND uep.send_email = 0)
group by user_id limit 100

It ignore user from user table which are having send_email = 1.

I want to join uep table only when user.id and send_email =0 else it should be not join and return only user details.

Sql Fiddle :http://www.sqlfiddle.com/#!2/1f083/2

Any help appricated!!

Author: Suresh Kamrushi
Posted: December 9, 2013, 1:39 pm

I have around 600k of image URLs in different tables and am downloading all the images with the code below and it is working fine. (I know FTP is the best option but somehow I can’t use it.)

$queryRes = mysql_query("SELECT url FROM tablName LIMIT 50000"); // everytime I am using LIMIT
while ($row = mysql_fetch_object($queryRes)) {
    $info = pathinfo($row->url);
    $fileName = $info['filename'];
    $fileExtension = $info['extension'];

    try {
        copy("http:".$row->url, "img/$fileName"."_".$row->id.".".$fileExtension);
    } catch(Exception $e) {
        echo "<br/>\n unable to copy '$fileName'. Error:$e";
    }
}

Problems are:

  1. After some time, say 10 minutes, scripts give 503 error. But still continue downloading the images. Why, it should stop copying it?
  2. And it does not download all the images, everytime there will be difference of 100 to 150 images. So how can I trace which images are not downloaded?

I hope I have explained well.

Author: Suresh Kamrushi
Posted: December 5, 2013, 5:40 am

Go to the Sql tab run one of the below query:

delete from tableName;

Delete: will delete all rows from your table. Next insert will take next auto increment id.

or

truncate tableName;

Truncate: will also delete the rows from your table but it will start from new row with 1.

A detailed blog with example: http://sforsuresh.in/phpmyadmin-deleting-rows-mysql-table/

Author: Suresh Kamrushi
Posted: August 16, 2013, 11:13 am

Instead of:

data:({channel: +channel}),

Try this:

data:{channel: channel},
Author: Suresh Kamrushi
Posted: March 27, 2013, 11:11 am

I have integrated Jstree in my application, now i want to understand different column in that table:

CREATE TABLE IF NOT EXISTS `tree` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `parent_id` bigint(20) unsigned NOT NULL,
  `position` bigint(20) unsigned NOT NULL,
  `left` bigint(20) unsigned NOT NULL,
  `right` bigint(20) unsigned NOT NULL,
  `level` bigint(20) unsigned NOT NULL,
  `title` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
  `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ;

This is the default table provided by the site.

Now if want to add a node, how do i know the value for left, right and level.

Author: Suresh Kamrushi
Posted: January 23, 2013, 10:49 am