<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: zeeshan mehdi</title>
    <description>The latest articles on DEV Community by zeeshan mehdi (@zeeshanmehdi).</description>
    <link>https://dev.to/zeeshanmehdi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F364208%2Fe92734ce-b197-4019-bf50-1e6bd8d2ddd5.jpg</url>
      <title>DEV Community: zeeshan mehdi</title>
      <link>https://dev.to/zeeshanmehdi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zeeshanmehdi"/>
    <language>en</language>
    <item>
      <title>Rules that i follow for clean Code</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Tue, 28 Jun 2022 20:36:23 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/rules-that-i-follow-for-clean-code-515c</link>
      <guid>https://dev.to/zeeshanmehdi/rules-that-i-follow-for-clean-code-515c</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Avoid Switch Statements instead use polymorphysm so for example you have a class Shape and there are few children like triangle, circle so in future if you want to add new shape like rectangle you can just inherit it from Shape and you do not have to change anything in the base class.&lt;/li&gt;
&lt;li&gt;Don't Pass more than three arguments instead pass an object&lt;/li&gt;
&lt;li&gt;Don't pass a boolean to a function&lt;/li&gt;
&lt;li&gt;Use functions inside if statements&lt;/li&gt;
&lt;li&gt;Clearly name your folders, modules, functions, classes, object and variables in a way that easily understandable what they do.&lt;/li&gt;
&lt;li&gt;Function has to do just one thing&lt;/li&gt;
&lt;li&gt;Function should not have more than 2 indents, ideally no ident.&lt;/li&gt;
&lt;li&gt;No side Effects  ( for example if you open a file ,you should not leave it open but close it after you are done with it.) &lt;/li&gt;
&lt;li&gt;Don't write any code inside try block instead just a function call.&lt;/li&gt;
&lt;li&gt;Don't duplicate code convert them to reusable methods.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I will write part 2 to this post.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>PHP Laravel authentication method unknown to the client [caching_sha2_password]</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Thu, 22 Apr 2021 02:09:12 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/php-laravel-authentication-method-unknown-to-the-client-cachingsha2password-2hod</link>
      <guid>https://dev.to/zeeshanmehdi/php-laravel-authentication-method-unknown-to-the-client-cachingsha2password-2hod</guid>
      <description>&lt;p&gt;I am using laravel 5.8 and having MAMP server got this error resolved by adding DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock in .env file like below&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DB_CONNECTION=mysql&lt;br&gt;
DB_HOST=127.0.0.1&lt;br&gt;
DB_PORT=8889&lt;br&gt;
DB_DATABASE=dbname&lt;br&gt;
DB_USERNAME=root&lt;br&gt;
DB_PASSWORD=root&lt;br&gt;
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>how to deploy Node js App to Cpanel or Shared Hosting</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Sat, 09 Jan 2021 14:57:23 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/how-to-deploy-node-js-app-to-cpanel-or-shared-hosting-2k0</link>
      <guid>https://dev.to/zeeshanmehdi/how-to-deploy-node-js-app-to-cpanel-or-shared-hosting-2k0</guid>
      <description>&lt;p&gt;I have made a video which thoroughly explains the process of deploying node js app with MySQL database to cpanel&lt;/p&gt;

&lt;p&gt;check video &lt;a href="https://www.youtube.com/watch?v=O3Tkpy_lVAA"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>cpanel</category>
      <category>beginners</category>
      <category>express</category>
    </item>
    <item>
      <title>Flutter : Could not find a generator for route RouteSettings(“/somePage”, null) in the _WidgetsAppState</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Sun, 27 Sep 2020 04:41:51 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/flutter-could-not-find-a-generator-for-route-routesettings-somepage-null-in-the-widgetsappstate-2pcp</link>
      <guid>https://dev.to/zeeshanmehdi/flutter-could-not-find-a-generator-for-route-routesettings-somepage-null-in-the-widgetsappstate-2pcp</guid>
      <description>&lt;h3&gt;
  
  
  Solution 1 :
&lt;/h3&gt;

&lt;p&gt;Use this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Navigator.push(context, new MaterialPageRoute(
   builder: (context) =&amp;gt; new MyHomePage())
 );

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Navigator.of(context)
           .pushReplacementNamed('/somePage');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but in my case it did not fixed.&lt;/p&gt;

&lt;p&gt;Let me explain what was problem in my case ,&lt;/p&gt;

&lt;p&gt;I had navigation drawer and one of my route was going to a route which  had another MaterialApp() Widget and after routing to that page if i route back to any other page it will through this exception. Do you know why ?&lt;/p&gt;

&lt;p&gt;because the context was changed to new material app and i was trying to find that route inside new material app but obviously it was not present there.&lt;/p&gt;

&lt;p&gt;Before&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class App extends StatelessWidget {
  final UserAndManagement userAndManagement;
  App(this.userAndManagement);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        fontFamily: "Varela",
        primaryColor: primaryMaterialColor
      ),
      home: HomePage(userAndManagement),
    );
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class App extends StatelessWidget {
  final UserAndManagement userAndManagement;
  App(this.userAndManagement);
  @override
  Widget build(BuildContext context) {
    return HomePage(userAndManagement);
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and You guess it worked for me like a charm !!!!&lt;/p&gt;

&lt;p&gt;If you were facing the same problem it fixed it give this thumbs up.&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

</description>
    </item>
    <item>
      <title>NOdejs MYSql Error: ER_TRUNCATED_WRONG_VALUE: Truncated incorrect DOUBLE value: 'admin1234'</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Sat, 19 Sep 2020 13:57:45 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/nodejs-mysql-error-ertruncatedwrongvalue-truncated-incorrect-double-value-admin1234-1pb9</link>
      <guid>https://dev.to/zeeshanmehdi/nodejs-mysql-error-ertruncatedwrongvalue-truncated-incorrect-double-value-admin1234-1pb9</guid>
      <description>&lt;p&gt;&lt;br&gt;
Code causing issue&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let query = `update users set email = ? and password = ? where id = ?`;
    console.log(query);
    connection.query(query,[id,email,pass], function(error, result, fields) {

        if (error) {
            console.log(`error ${error}`);
            callback(false);
        }else {
            console.log(result);
            if(result.affectedRows&amp;gt;0)
                callback(true);
            else
                callback(false);
        }
    });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;solution : Just replace AND with comma&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let query = `update users set email = ?,password = ? where id = ?`;
    console.log(query);
    connection.query(query,[id,email,pass], function(error, result, fields) {

        if (error) {
            console.log(`error ${error}`);
            callback(false);
        }else {
            console.log(result);
            if(result.affectedRows&amp;gt;0)
                callback(true);
            else
                callback(false);
        }
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Node js Left Join with limit and offset Mysql</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Sat, 19 Sep 2020 08:14:47 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/node-js-left-join-with-limit-and-offset-msql-2k1o</link>
      <guid>https://dev.to/zeeshanmehdi/node-js-left-join-with-limit-and-offset-msql-2k1o</guid>
      <description>&lt;p&gt;&lt;br&gt;
&lt;strong&gt;I was having a scenario where i was required to add pagination to website without using any plugin so i started, i knew how to use limit and offset but with joins it was a problem so after searching around i found the solution here it is .&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let query = `select audio.title as title, audio.artist ,audio.fileName, audio.date,album.title as albumtitle from audio   left join album on audio.album = album.id order by audio.id LIMIT 10 offset ${offset}`;
    console.log(query);
    connection.query(query, function(error, result, fields) {

        if (error) {
            console.log(`error ${error}`);
            callback(error, null);
        }else {
            console.log(result);
            callback('success', result);
        }
    });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;result on console&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select audio.title as title, audio.artist ,audio.fileName, audio.date,album.title as albumtitle from audio   left join album on audio.album = album.id order by audio.id LIMIT 10 offset 0
[
  RowDataPacket {
    title: 'Audio Title',
    artist: null,
    fileName: 'audio-1600246003244ha.mp3',
    date: 2020-09-16T08:46:43.000Z,
    albumtitle: 'Jal Pari'
  },
  RowDataPacket {
    title: 'Another audio',
    artist: null,
    fileName: 'audio-1600246030100gs.mp3',
    date: 2020-09-16T08:47:10.000Z,
    albumtitle: 'Jal Pari'
  },
  RowDataPacket {
    title: 'Some title',
    artist: null,
    fileName: 'audio-1600246129892gs.mp3',
    date: 2020-09-16T08:48:50.000Z,
    albumtitle: 'Jal Pari'
  },
  RowDataPacket {
    title: 'Upload Another',
    artist: null,
    fileName: 'audio-1600246160918la.mp3',
    date: 2020-09-16T08:49:21.000Z,
    albumtitle: null
  },
  RowDataPacket {
    title: 'Tere sang yaara',
    artist: 'Atif Aslam',
    fileName: 'audio-1600349287336an.mp3',
    date: 2020-09-17T13:28:07.000Z,
    albumtitle: null
  }
]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it helped you make sure to give thumbs up. thanks&lt;/p&gt;

</description>
      <category>node</category>
      <category>sql</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Uploading multiple files with multer, but from different fields Node JS</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Thu, 17 Sep 2020 14:11:26 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/uploading-multiple-files-with-multer-but-from-different-fields-node-js-58d6</link>
      <guid>https://dev.to/zeeshanmehdi/uploading-multiple-files-with-multer-but-from-different-fields-node-js-58d6</guid>
      <description>&lt;h4&gt;
  
  
  i was in a situation where i were to upload audio file along with a graphic for that particular song so i was to upload to different files an image and audio file so i used a way to do that using multer plugin available on &lt;a href="https://www.npmjs.com/"&gt;link&lt;/a&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var multer = require('multer')
var storage = multer.diskStorage({


destination: function(req, file, callback) {
    callback(null, './public/audio');
  },
  filename: function(req, file, callback) {
    console.log(file);
    if(file.originalname.length&amp;gt;6)
      callback(null, file.fieldname + '-' + Date.now() + file.originalname.substr(file.originalname.length-6,file.originalname.length));
    else
      callback(null, file.fieldname + '-' + Date.now() + file.originalname);

  }
});

const upload = multer({ storage: storage });


router.post('/save/audio',upload.fields([{
  name: 'audio', maxCount: 1
}, {
  name: 'graphic', maxCount: 1
}]) ,(req, res) =&amp;gt; {

  const audioFile = req.files.audio[0];
  const audioGraphic = req.files.graphic[0];
  const fileName = req.body.title;


  saveAudio(fileName,audioFile.filename,audioGraphic.filename,req.body.artist,function (error,success) {
    req.flash('success','File Uploaded Successfully')

    res.redirect('/')
  });

})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>node</category>
      <category>backend</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>how to send push notification to particular user using fcm (firebase Messaging) and Flutter</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Mon, 13 Apr 2020 16:09:41 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/how-to-send-push-notification-to-particular-user-using-fcm-firebase-massaging-and-flutter-j95</link>
      <guid>https://dev.to/zeeshanmehdi/how-to-send-push-notification-to-particular-user-using-fcm-firebase-massaging-and-flutter-j95</guid>
      <description>&lt;p&gt;Notification Sending Side Using Dio flutter Library to make http post request&lt;/p&gt;

&lt;p&gt;step1 : Get api key from firebase console under firebase messaging section or from project settings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var postUrl = "fcm.googleapis.com/fcm/send";

        static Future&amp;lt;void&amp;gt; sendNotification(receiver,msg)async{

        var token = await getToken(receiver);
        print('token : $token');

        final data = {
          "notification": {"body": "Accept Ride Request", "title": "This is Ride Request"},
          "priority": "high",
          "data": {
            "click_action": "FLUTTER_NOTIFICATION_CLICK",
            "id": "1",
            "status": "done"
          },
          "to": "$token"
        };

        final headers = {
          'content-type': 'application/json',
          'Authorization': 'key=&amp;lt;Your firebase Messaging Api Key Get it from firebase project settings under cloud messaging section&amp;gt;'
        };


        BaseOptions options = new BaseOptions(
          connectTimeout: 5000,
          receiveTimeout: 3000,
          headers: headers,
        );


        try {
          final response = await Dio(options).post(postUrl,
              data: data);

          if (response.statusCode == 200) {
            Fluttertoast.showToast(msg: 'Request Sent To Driver');
          } else {
            print('notification sending failed');
            // on failure do sth
          }
        }
        catch(e){
          print('exception $e');
        }




      }

      static Future&amp;lt;String&amp;gt; getToken(userId)async{

        final Firestore _db = Firestore.instance;

        var token;
        await _db.collection('users')
            .document(userId)
            .collection('tokens').getDocuments().then((snapshot){
              snapshot.documents.forEach((doc){
                token = doc.documentID;
              });
        });

        return token;


      }


    //Now Receiving End 

        class _LoginPageState extends State&amp;lt;LoginPage&amp;gt;
        with SingleTickerProviderStateMixin {

      final Firestore _db = Firestore.instance;
      final FirebaseMessaging _fcm = FirebaseMessaging();

      StreamSubscription iosSubscription;



    //this code will go inside intiState function 

    if (Platform.isIOS) {
          iosSubscription = _fcm.onIosSettingsRegistered.listen((data) {
            // save the token  OR subscribe to a topic here
          });

          _fcm.requestNotificationPermissions(IosNotificationSettings());
        }
        _fcm.configure(
          onMessage: (Map&amp;lt;String, dynamic&amp;gt; message) async {
            print("onMessage: $message");
            showDialog(
              context: context,
              builder: (context) =&amp;gt; AlertDialog(
                content: ListTile(
                  title: Text(message['notification']['title']),
                  subtitle: Text(message['notification']['body']),
                ),
                actions: &amp;lt;Widget&amp;gt;[
                  FlatButton(
                    child: Text('Ok'),
                    onPressed: () =&amp;gt; Navigator.of(context).pop(),
                  ),
                ],
              ),
            );
          },
          onLaunch: (Map&amp;lt;String, dynamic&amp;gt; message) async {
            print("onLaunch: $message");
            // TODO optional
          },
          onResume: (Map&amp;lt;String, dynamic&amp;gt; message) async {
            print("onResume: $message");
            // TODO optional
          },
        );

//saving token while signing in or signing up
 _saveDeviceToken(uid) async {
    FirebaseUser user = await _auth.currentUser();

    // Get the token for this device
    String fcmToken = await _fcm.getToken();

    // Save it to Firestore
    if (fcmToken != null) {
      var tokens = _db
          .collection('users')
          .document(uid)
          .collection('tokens')
          .document(fcmToken);

      await tokens.setData({
        'token': fcmToken,
        'createdAt': FieldValue.serverTimestamp(), // optional
        'platform': Platform.operatingSystem // optional
      });
    }
  }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;libs used firebase messaging, Dio for http request and firestore to store and retrieve fcm token. &lt;/p&gt;

</description>
      <category>flutter</category>
      <category>tutorial</category>
      <category>notification</category>
      <category>beginners</category>
    </item>
    <item>
      <title>I am new here</title>
      <dc:creator>zeeshan mehdi</dc:creator>
      <pubDate>Fri, 10 Apr 2020 12:54:34 +0000</pubDate>
      <link>https://dev.to/zeeshanmehdi/i-am-new-here-2e17</link>
      <guid>https://dev.to/zeeshanmehdi/i-am-new-here-2e17</guid>
      <description>&lt;p&gt;New Here ..&lt;/p&gt;

&lt;h1&gt;
  
  
  newcommer
&lt;/h1&gt;

</description>
    </item>
  </channel>
</rss>
