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

what you want to fix?
Author: Suresh Kamrushi
Posted: July 31, 2018, 11:42 am

Go to Menu and select Tools => NuGet Package Manager => Package Manager Console and type the below command:

PM> Install-Package NuGet.Client -Version 4.2.0 

For more info: https://www.nuget.org/packages/NuGet.Client/

Author: Suresh Kamrushi
Posted: July 31, 2018, 10:58 am
what went wrong? what error you are getting
Author: Suresh Kamrushi
Posted: July 25, 2018, 10:28 am

You can try google api: https://www.phpflow.com/php/currency-converter-in-php-using-google-api/

function currencyConverter($from_currency, $to_currency, $amount) {
$amount    = urlencode($amount);
$from    = urlencode($from_currency);
$to        = urlencode($to_currency);
$url    = "http://www.google.com/ig/calculator?hl=en&q=$amount$from=?$to";
$ch     = @curl_init();
$timeout= 0;

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];
return round($var,3);
}
?>
Author: Suresh Kamrushi
Posted: July 25, 2018, 8:01 am
what you have tried so far?
Author: Suresh Kamrushi
Posted: July 25, 2018, 7:59 am

You can try this:

select (parent.salary - (select ch.salary from a_test as ch where ch.emp_id = parent.emp_id order by id desc limit 1,1)) as diff, emp_id, name, salary, month from a_test as parent where month = 'feb';

Sql Fiddle: http://sqlfiddle.com/#!9/52a019/2

You can add/update where condition in main and sub query to have month dynamically. like below:

where month = MONTHNAME(CURRENT_DATE())
Author: Suresh Kamrushi
Posted: July 25, 2018, 6:43 am

Using ScrollX or scrollY create such problems. there is a work around for it:

$('#userslist').DataTable({            
  "initComplete": function (settings, json) {  
    $("#reportDetails").wrap("<div style='overflow:auto; width:100%;position:relative;'></div>");            
  },
});

First remove ScrollX or scrollY if you have in your page and add above code to fix it.

Author: Suresh Kamrushi
Posted: July 20, 2018, 7:08 am
Author: Suresh Kamrushi
Posted: July 20, 2018, 5:22 am

Try below:

$('#adsensebanner', window.parent.document).addClass("addedclass");
Author: Suresh Kamrushi
Posted: July 19, 2018, 9:05 am
refreash page/content periodically either by ajax or meta tag.
Author: Suresh Kamrushi
Posted: June 1, 2018, 11:33 am

You can validate using Javascript like below:

var b = url.search(/(?:https?|ftp):\/\/[\n\S]+/g);

Fiddle : https://jsfiddle.net/uzo8j806/9/

Author: Suresh Kamrushi
Posted: April 9, 2018, 8:12 am

do something like this:

$(document).on('change','#startdate',function () { 
alert('h');
});

As per your comment you can try like:

$('#startdate').on('change','#startdate',function () { 
alert('h');
});
Author: Suresh Kamrushi
Posted: April 6, 2018, 8:57 am

For C# MVC 4.5 you need to do like this:

Response.Clear();
Response.ContentType = "application/CSV";
Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + ".csv\"");
Response.Write(dataNeedToPrint);
Response.End();
return new EmptyResult();  //this line is important else it will not work.
Author: Suresh Kamrushi
Posted: March 27, 2018, 11:35 am

You can try something like below:

string Text="22/11/2009";
DateTime date = DateTime.ParseExact(Text, "dd/MM/yyyy", null);              
Console.WriteLine("update date => "+date.ToString("yyyy-MM-dd"));
Author: Suresh Kamrushi
Posted: March 23, 2018, 10:07 am

None of the above answer worked for me. Sharing what worked:

string Text="22/11/2009";
DateTime date = DateTime.ParseExact(Text, "dd/MM/yyyy", null);              
Console.WriteLine("update date => "+date.ToString("yyyy-MM-dd"));
Author: Suresh Kamrushi
Posted: March 23, 2018, 10:04 am

you can try somethig like this:

   $datetime1 = date_create($date_1);
    $datetime2 = date_create($date_2);

    $interval = date_diff($datetime1, $datetime2);   
    $interval->format($differenceFormat);

reff :http://php.net/manual/en/function.date-diff.php

Author: Suresh Kamrushi
Posted: February 26, 2018, 4:07 am

You need to add following attribute to the link or button where you want add this functionality:

 data-dismiss="modal" data-toggle="modal" id="forgotPassword" data-target="#ModalForgotPassword"

A detaile blog: http://sforsuresh.in/bootstrap-modal-window-close-current-open-new-modal/

Author: Suresh Kamrushi
Posted: February 13, 2018, 6:00 am

I am getting error: tried using like: "useClass: ApidataService" or "ApidataService" in providers and also remove public from the service constructor.

Failed to compile.

C:/wamp64/www/angular/project/src/app/app.module.ts (33,69): Argument of type '{ declarations: (typeof AppComponent | typeof ViewComponent | typeof AboutComponent | typeof News...' is not assignable to parameter of type 'NgModule'.
  Types of property 'providers' are incompatible.
    Type '{ provide: InjectionToken<string>; useValue: string; ApidataService: typeof ApidataService; }[]' is not assignable to type 'Provider[]'.
      Type '{ provide: InjectionToken<string>; useValue: string; ApidataService: typeof ApidataService; }' is not assignable to type 'Provider'.
        Object literal may only specify known properties, and 'ApidataService' does not exist in type 'Provider'.

My service is:

import { Injectable } from '@angular/core';

@Injectable()
export class ApidataService {

  public  constructor() { }
    cars = ['cars','bycycle','van'];
    mydata(){
        return "this is from apidata";
    }
}

And app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { ViewComponent } from './view/view.component';
import { AboutComponent } from './about/about.component';
import { RouterModule, Routes} from '@angular/router';
import { NewsComponent } from './news/news.component';
import {APP_BASE_HREF} from '@angular/common';
import { FormsModule } from '@angular/forms';   //for 2way binding

//SERVICES SAMPLE
import {ApidataService} from './apidata.service';

@NgModule({
  declarations: [
    AppComponent,
    ViewComponent,
    AboutComponent,
    NewsComponent    
  ],
  imports: [
    HttpModule,
    BrowserModule,
    FormsModule,
    RouterModule.forRoot([
        {path:'About',component:AboutComponent},
        {path:'News',component:NewsComponent}
    ])
  ],
    providers: [
        {provide: APP_BASE_HREF, useValue: 'http://localhost:4200/',ApidataService}
     ],
  bootstrap: [AppComponent]
})

export class AppModule { }
Author: Suresh Kamrushi
Posted: February 9, 2018, 6:15 am

With angular 4 you can fix this issue by updating app.module.ts file as follows:

Add import statement at the top as below:

import {APP_BASE_HREF} from '@angular/common';

And add below line inside @NgModule

providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]

Reff: https://angular.io/api/common/APP_BASE_HREF

Author: Suresh Kamrushi
Posted: February 2, 2018, 12:20 pm

working example of jsgrid date field

var db = {

    loadData: function(filter) {
        return $.grep(this.users, function(user) {
            return (!filter.Name || user.Name.indexOf(filter.Name) > -1);
        });
    },

    insertItem: function(item) {
        this.users.push(item);
    },

    deleteItem: function(item) {
        var index = $.inArray(item, this.users);
        this.users.splice(index, 1);
    }

};

window.db = db;

db.users = [
    {
        "Account": "D89FF524-1233-0CE7-C9E1-56EFF017A321",
        "Name": "Prescott Griffin",
        "RegisterDate": "2011-02-22T05:59:55-08:00"
    },
    {
        "Account": "06FAAD9A-5114-08F6-D60C-961B2528B4F0",
        "Name": "Amir Saunders",
        "RegisterDate": "2014-08-13T09:17:49-07:00"
    },
    {
        "Account": "EED7653D-7DD9-A722-64A8-36A55ECDBE77",
        "Name": "Derek Thornton",
        "RegisterDate": "2012-02-27T01:31:07-08:00"
    },
    {
        "Account": "2A2E6D40-FEBD-C643-A751-9AB4CAF1E2F6",
        "Name": "Fletcher Romero",
        "RegisterDate": "2010-06-25T15:49:54-07:00"
    },
    {
        "Account": "3978F8FA-DFF0-DA0E-0A5D-EB9D281A3286",
        "Name": "Thaddeus Stein",
        "RegisterDate": "2013-11-10T07:29:41-08:00"
    }
];

var MyDateField = function (config) {
    jsGrid.Field.call(this, config);
};

MyDateField.prototype = new jsGrid.Field({

    sorter: function (date1, date2) {
        return new Date(date1) - new Date(date2);
    },

    itemTemplate: function (value) {
        return new Date(value).toDateString();
    },

    insertTemplate: function (value) {
        return this._insertPicker = $("<input class='date-picker'>").datetimepicker();
    },

    editTemplate: function (value) {
        return this._editPicker = $("<input class='date-picker'>").datetimepicker();
    },

    insertValue: function () {
        return this._insertPicker.data("DateTimePicker").useCurrent();
    },

    editValue: function () {
        return this._editPicker.data("DateTimePicker").useCurrent();
    }
});

jsGrid.fields.date = MyDateField;

$("#jsGrid").jsGrid({
    height: "90%",
    width: "100%",

    inserting: true,
    filtering: true,
    editing: true,
    paging: true,

    autoload: true,

    controller: db,

    fields: [
        { name: "Account", width: 150, align: "center" },
        { name: "Name", type: "text" },
        { name: "RegisterDate", type: "date", width: 100, align: "center" },
        { type: "control", editButton: false }
    ]
});

Refference: http://jsfiddle.net/tabalinas/L6wbmvfo/

Author: Suresh Kamrushi
Posted: January 30, 2018, 8:05 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

Is there any library/class/plugin available for generating QR code and Barcode?
I am getting is two different libraries for each one of them.
It will be good if I can get in single library with both functionality.

After google I found few links like this:

https://github.com/dwisetiyadi/CodeIgniter-PHP-QR-Code
https://www.sitepoint.com/generate-qr-codes-in-php/

Author: Suresh Kamrushi
Posted: May 2, 2017, 7:39 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

Try this-

CREATE PROCEDURE simpleproc (IN name varchar(50),IN user_name varchar(50),IN branch varchar(50))
BEGIN
    insert into student (name,user_name,branch) values (name ,user_name,branch);
END
Author: Suresh Kamrushi
Posted: February 22, 2013, 6:56 am