What is Nitrous and How can code on browser?

Hey guys,

I just uploaded a video on my channel, I tired to explained about one of the coolest cloud service that I have seen, it helps you to code on PHP,Node.Js and so many other languages just on your browser without installing any extra tools or application on your machine.

enjoy the video.

Advertisement

Create and Read Excel File in C#

Hello guys šŸ™‚

It is very common for applications to have import or export in excel format. There are plenty options that you can use to read or write an excel file in .net. Today I am going to introduce you two simple libraries that are open source and can help you in reading and writing excel files in any type of .net applications.

 

Here is a simple code that create an excel file by using EPPluslibrary, you can download the full source code directly from my git-hub

Before you start coding you need to make sure that you have imported these libraries :

 


using Excel;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

Creating Excel:


public string CreateExcelFile(DirectoryInfo outputDir)
{

FileInfo newFile = new FileInfo(outputDir.FullName + @"\sample1.xlsx");
if (newFile.Exists)
{
newFile.Delete();Ā  // ensures we create a new workbook
newFile = new FileInfo(outputDir.FullName + @"\sample1.xlsx");
}
using (ExcelPackage package = new ExcelPackage(newFile))
{
// add a new worksheet to the empty workbook

ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Student Lists");
//HereĀ  column toĀ  the current sheet
worksheet.Cells[1, 1].Value = "Title";
worksheet.Cells[1, 2].Value = "Name";
worksheet.Cells[1, 3].Value = "Family";
worksheet.Cells[1, 4].Value = "Student Code";

//Add value to celles

worksheet.Cells[2, 1].Value = "Mr.";
worksheet.Cells[2, 2].Value = "Mehran";
worksheet.Cells[2, 3].Value = "Janfeshan";
worksheet.Cells[2, 4].Value = "ST54516";

worksheet.Cells.AutoFitColumns(0);Ā  //Autofit columns for all cells
worksheet.HeaderFooter.OddFooter.RightAlignedText =
string.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
// add the sheet name to the footer
worksheet.HeaderFooter.OddFooter.CenteredText = ExcelHeaderFooter.SheetName;
//Save and export excel file

package.Save();

}

return newFile.FullName;
}

Reading Excel :


public DataSet ReadExcel()
{
string filePath;
filePath = "C:\\sample1.xlsx";
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
excelReader.Close();
return result;
}

Please contact me if you have any issue with the code.

How can create Module in Node.js and reference them in any js file?

Hey guys,

Node.js same as other programming languages supports module. Basically modules help us to have better structure for our application and also it let you to maintain your application easily. For example you have an application that are doing these tasks:

1. Send email
2. Grab files from FTP
3. Create output files and upload into FTP
Each of these tasks can be a separate module, for those that are familiar with object oriented programing, module can play the same role as class. Module is not something new in Node.js but you must know how to define module and how import them to your app.js or anywhere that you want to use them.
Follow these few steps:
1. Create a js file in root folder. ( you need to have node folder, if you do not know what is node folder you can first look at this post)
2. Each module can have two types of function.
2.1. Public function which others can call this function and it is like interface for the module.
2.2. Private function which is used by other functions inside the module and others from outside cannot use it.
3. Copy can past these code inside the js file.

var name;




exports.getname = function(inputname){
     name=inputname;

}


exports.Printname = function(){
   console.log(name);

}

This is a very simple example of module, in this module we have a global variable which is name and two functions, first is getname which gets name and the other one is Printname which prints out the name. To make a function public we need to export it.

How can call a module?
It is very easy, first you need to import your module, in this example I want to import the module in app.js file but it can be imported in any other js file, based on your need. To impost any module you must use this command:


var testmodule = require("./getname.js");

require is something like import in vb.net or using in C#, if your module installed inside the node_modules folder, then you do not need to mention any path an straight you can name the module. But if your js is in the root then you can access to it thru this address:

(“./getname.js”) // Name can be anything based on your module name

ā€œRequireā€ creates an object from the module, so after that you can access all exported function via that object:


testmodule.getname('Mehran');
testmodule.Printname();

I hope this example helps you to understand Node module better, Node.js is like a puzzle you need to spend time to understand the whole story, and it may not be easy as the environment and concept is a bit different with what we used to it.

you can download full set of code form my github :

https://github.com/CodingTips/tutorial

for any questions you can contact me through my email :
janfeshan.mehran@gamil.com

bye bye

What is Git and why should I use Git?

Hey Guys

I believe, If Microsoft starts working on something or if it buys a start-up company you must take it serious. We all know that Microsoft left behind in so many things same as Mobile, tablet and even Cloud that’s why it is trying to buy new companies or include new technologies inside its product . Any way I want to talk about Git as Microsoft supports it.

Let see what Git is:

I am sure most of you heard about source control if even you have not used it yet. Source control is not a new term in developing and programing world. Developers always were looking for a tool that can help them to keep track of the changes on the code and help them to control the version of application. Ā Demands for source control became more and more as IT industry expanded its own in every angle of our life. And development companies needed source control to let different member of a team work in one project at same time to develop it faster. Microsoft came with Source Safe and then upgrade it to TFS (team foundation server) and of course other companies came with other source control same as PVSC, Vault, and Perforce and etc. Ā I can say all of these products were awesome and still TFS is one the first choice for most of Microsoft based developer. But as a developer we always must look around for better options. One of the best option is Git. Git is an open source, source control which is developed by founder of Linux (Linus Torvalds) at that time he wanted to have a source control with special features for linux development team, finally he found out that there is no such product in the market so he decided to build his own source control and finally he came with Git, if you want to read more about the history of Git you can find it here.

Basically there are two types of source code control

  1. Centralized source control same TFS and source Safe.
  2. Distributed source control same Git.

In centralized source control live connection to the server is mandatory for any check in and check out and all clients must get the latest version from centralized repository. But on the other hand in distributed source control, each client has all source code plus all the histories of source code, and also each client has own repository, but it does not mean that there is no centralized repository.

I should say that the logic behind centralized and distributed is totally different, that’ why when someone like me wants to move from TFS to Git, he may feel uncomfortable and I am sure you may tell yourself that TFS is much more better. I should say that this kind of feeling when you are moving from current source control to Git is very normal. But once you understood the concept of Git, you can see that Git is much more better than your current source control and it will give you much freedom and features that you cannot have it in an application same as TFS. First I wanted to record a video and show you how to use TFS but later I found a very good recorded video and I decided to post the link here, I suggest you before start any search about Git, watch this video. It can help you a lot and you may not need any other tutorial.

Video Link :

https://www.microsoftvirtualacademy.com/en-us/training-courses/using-git-with-visual-studio-2013-jump-start-8306

If you have any question you can leave a comment here or always you can contact me via email:

janfeshan.mehran@gmail.com

bye bye

How can connect to the MongoDB through Node.js?

Hey guys,
Today I am going to show you how connect to MongoDB through Node.js. Please follow the below steps:
Note: for those that do not know how to install and use MongoDB please what this Video or ready this post
Note: I am using Webstorm to develop Node.js, you can install 30 days trail version and if you found it is good then buy it or you can use Code IDE which is an IDE that is provided by Microsoft and it is free 
If you use Webstorm, it creates everything for you and you only need to change the code and no need to be worry about the packages and other settings that normally needed for Node.js, here is my Webstorm screen:

There are different libraries that can help you to connect to MongoDB, for this tutorial I am using monk, which is simple and very light.
1. Add these few lines of code to app.js file :


var mong = require('mongodb'); // we import MongoDB
// library to our project
var monk = require('monk');// we create an object 
//from monk liberay in order to connect to MongoDb
var db = monk('localhost:27017/userlist');// we create an database 
//object which is connected to our ruing MongoDB instance

2. In the next step we need to set db in all requests that come to our server, it is a bit different with what we have done in ASP.net. you must be aware that concept in Nodde.js is very different with what you know in ASP.net or even Java.


app.use(function(req,res,next){
req.db = db;
next();
});

3. This few lines of code must be add before:


app.use('/', routes);
app.use('/users', users);

4. After these two simple steps, our app.js is ready to connect to MongoDB and gave service to rest of application. Now we need to add two functions to our route and create two more views in order to show the result and get data from user. Direct go to the route folder and open index.js and add these two functions:

Get data:


router.get('/userlist',function(req,res){
var db= req.db;
var collection=db.get('testcollection');
collection.find({},{},function(e,docs){

res.render('userlist',{"userlist":docs

});

});

});

Receive post request and insert in database.

router.post('/adduser', function(req, res) {

// Set our internal DB variable
var db = req.db;

// Get our form values. These rely on the "name" attributes
var userName = req.body.username;
var userEmail = req.body.useremail;

// Set our collection
var collection = db.get('testcollection');

// Submit to the DB
collection.insert({
"name" : userName,
"email" : userEmail
}, function (err, doc) {
if (err) {
// If it failed, return error
res.send("There was a problem adding the information to the database.");
}
else {
// And forward to success page
res.redirect("userlist");
}
});
});

We need two different views for these two functions, To add view, straight go to the view folder, copy and paste index.jade and change name to userlist ‘and do the same and name it adduser.

Open userlist and copy this code there:

extends layout

block content
h1.
User List
ul
each user, i in userlist
li
a(href="mailto:#{user.email}")= user.name

Open adduser and copy this code there:

extends layout
block content
h1= title
form#formAddUser(name="adduser",method="post",action="/adduser")
input#inputUserName(type="text", placeholder="username", name="username")
input#inputUserEmail(type="text", placeholder="useremail", name="useremail")
button#btnSubmit(type="submit") submit

I tried to explain everything in a short way. I will try to upload and video to show you everything.

Run your project and go to these two address to see your result:

http://localhot:3000/userlist

http://localhot:3000/adduser

Bye bye

Why does Cisco VPN Client minimize to task bar and cannot be maximised ?

Hey Guys,

This is a good question that may be asked thousand or even million times on the internet.

Why does Cisco VPN Client minimize to task bar and cannot be maximised?

Well, I do not know why it happens for Cisco VPN but I know how to fix it šŸ™‚

you just need to follow these five steps:

  1. go tho this address :

Ā Ā Ā Ā Ā Ā Ā  C:\Program Files (x86)\Cisco Systems\VPN Client
Address can be different based on the directory that you have chosen during installation. I am using windows 10 and this the directory that I have installed my VPN. ( Are you surprised that how I installed Cisco VPN Client on windows 10? Ok check my blog I already explained it there)

Ā  2. In the directory look for vpnclient.iniĀ  and open the file in the notepad.
Note : before you change anything in this file, please make a backup.

3. Inside the file look for :

WindowX=4343423
WindowY=4342423

Note: maybe the numbers are different on your file.

4. As you can see these numbers are so big, you need to change it to something smaller, for example 1000 or even less. up to you.

5. Save the file and open Cisco VPN Client and enjoy it.

Bye bye