Pad numbers with leading and ending zeros

0

In a recent project, I got a list of integers something similar to following.

1
12
123
1234
12345
….
123456789

and, I was asked to add zeros to the left or right of the list and make it as below.

List 1:
0000000001
0000000012
0000000123
…..
0123456789

List 2:
1000000000
1200000000
1230000000
….
1234567890

C# – PadLeft / PadRight

In C#, you can use PadLeft and PadRight functions to do this.
https://msdn.microsoft.com/en-us/library/system.string.padleft(v=vs.110).aspx

String.PadLeft Method (Int32, Char)
String.PadRight Method (Int32, Char)

int[] numbers = { 1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789 };

Console.WriteLine("List 1");
foreach (var i in numbers)
{
Console.WriteLine(i.ToString().PadLeft(10, '0'));
}

Console.WriteLine();
Console.WriteLine("List 2");
foreach (var i in numbers)
{
Console.WriteLine(i.ToString().PadRight(10, '0'));
}

 

PadLeft and PadRight

PadLeft and PadRight

SQL

Here comes the interesting part, I had to do this using SQL. In SQL there are no inbuilt PadLeft or PadRight functions.  So, I have used the LEFT and RIGHT SQL functions with a small hack.

CREATE TABLE [dbo].[NumberPadding](
[Number] [int] NOT NULL
) ON [PRIMARY]
GO;

INSERT INTO dbo.NumberPadding
VALUES (1), (12), (123), (1234), (12345), (123456), (1234567), (12345678), (123456789)
GO;

SELECT LEFT (CAST([Number] AS VARCHAR) + '0000000000', 10) FROM dbo.NumberPadding;

SELECT RIGHT ('0000000000' + CAST([Number] AS VARCHAR) , 10) FROM dbo.NumberPadding;
SQL - LEFT, RIGHT FUNCTIONS

SQL – LEFT, RIGHT FUNCTIONS

 

 

Just Learned: Self-XSS

0

Have you ever tried chrome inspector with Facebook? If so, I am sure you have seen this. This warning message is to help prevent Self-XSS scams.

Facebook-Self-XSS-Warning

Self-XSS

Self-XSS is a social engineering attack that is designed to gain control of your social media account. In a self-XSS attack, an attacker convinces a user to runs malicious code on the address bar of his/her web browser.

Following video covers both share-baiting (a pure social engineering attack) and self-XSS (a combination of social engineering and a browser vulnerability).

 

Addition Reference:

How to create formatted console.log message

https://developer.chrome.com/devtools/docs/console

console.log ("%cThis will be formatted with large, blue text", "color: blue; font-size: x-large");

Formatted Crome Console

How Facebook disabled Chrome developer console earlier

http://stackoverflow.com/questions/21692646/how-does-facebook-disable-the-browsers-integrated-developer-tools/21692733#21692733

Generate insert statements from the specific table data using SQL Server

0

When you are deploying your application, sometimes you may want to generate SQL script with the insert statement of the specific database table. The following article shows two easiest ways to do this with SQL Server and SQL Server tools.

  1. Using Database Publishing Wizard (“SqlPubWiz.exe”)

If you install Visual Studio 2008 / Visual Studio 2008 Express full version, it automatically installs the Microsoft SQL Server Data Publishing Wizard in the following location.
[SQL Server Installation Location]\90\Tools\Publishing[version]\ SqlPubWiz.exe

If it is not there, you can download it from the following URL
http://go.microsoft.com/fwlink/?LinkId=119368

SQLPubWiz location

SQLPubWiz location

When you run the “SqlPubWiz.exe”, it opens the database publishing wizard

Database Publishing Wizard

Database Publishing Wizard

Click next and enter the database server connection information accordingly.

Database Publishing Wizard - Database Server Connection

Database Publishing Wizard – Database Server Connection

Click next, and it asks you to select the database, which you want to generate the data from

Database Publishing Wizard - Select Database

Database Publishing Wizard – Select Database

Next screen asks to select the Object type. You can use this database publishing wizard to generate data and schema both. In here I consider only for the data generation part. Now choose “Tables” as an option and click next. (Make sure to uncheck “Script all objects in the selected database”)

Database Publishing Wizard - Choose Object Type

Database Publishing Wizard – Choose Object Type

Then, the next ask to select the table that you want to generate the data from. Select whatever the table you want and click next.

Database Publishing Wizard - Choose Tables

Database Publishing Wizard – Choose Tables

Next step asks to specify the output location. You can enter the file name and the location there.

Database Publishing Wizard - Select an Output Location

Database Publishing Wizard – Select an Output Location

By clicking Next, It shows to choose the publishing options. There are three publishing types, Schema only, Data only, or Schema and data. Here you have to select “Data only”.

Database Publishing Wizard - Select Publishing Option

Database Publishing Wizard – Select Publishing Option

Click next and it generates the insert data script for you.

Database Publishing Wizard - Publishing Progress

Database Publishing Wizard – Publishing Progress

Database Publishing Wizard - Generated Script

Database Publishing Wizard – Generated Script

  1. Using SQL Server Generate Script wizard
SQL Server Generate Script

SQL Server Generate Script

When you select “Generate Script” menu item, it opens the Generate SQL Server Scripts Wizard dialog.

SQL Server Generate Script - Wizard Dialog

SQL Server Generate Script – Wizard Dialog

By clicking next, it asks to select the database that you want to generate the script.

SQL Server Generate Script Wizard - Select Database

SQL Server Generate Script Wizard – Select Database

By clicking Next, It shows to select the script options dialog box. In here, you change the “Script Data” as “True” and click the next button

SQL Server Generate Script Wizard - Choose Script Option

SQL Server Generate Script Wizard – Choose Script Option

Next screen asks to select the Object type. Now choose “Tables” as an option and click next.

SQL Server Generate Script Wizard - Choose Object Type

SQL Server Generate Script Wizard – Choose Object Type

Next screen asks you to select the tables that you want to generate the data from. Select whatever the tables and click next

SQL Server Generate Script Wizard - Choose Tables

SQL Server Generate Script Wizard – Choose Tables

Next step asks to specify the output options. If you select “Script to file” as an option, then you can enter the file name and the location there.

SQL Server Generate Script Wizard - Output Option

SQL Server Generate Script Wizard – Output Option

Next two steps are very straight forward. It shows the script generation summary, and by clicking next it generates the script with insert statements for the selected tables.

SQL Server Generate Script Wizard - Script Summary

SQL Server Generate Script Wizard – Script Summary

SQL Server Generate Script Wizard - Script Progress

SQL Server Generate Script Wizard – Script Progress

SQL Server Generate Script Wizard - Generated Script

SQL Server Generate Script Wizard – Generated Script

SMTP, POP3 and IMAP

0

SMTP, POP3 and IMAP are TCP/IP protocols used for mail delivery. Email clients use POP3 and IMAP protocol to retrieve email from the server (incoming mail) over TCP/IP connection. Outgoing mail for both POP and IMAP clients uses the SMTP. Main difference between POP3 and IMAP is,

  • POP3 – Downloads email locally
  • IMAP – Mail is stored on the mail server

SMTP

Simple Mail Transfer Protocol (SMTP) servers handle the sending of your e mail messages to the Internet. The SMTP server handles outgoing e mail, and is used in conjunction with a POP3 or IMAP incoming e mail server.

POP3

Post Office Protocol 3 (POP3) servers hold incoming e mail messages until you check your e mail, at which point they’re transferred to your computer. POP3 is the most common account type for personal e mail. Messages are typically deleted from the server when you check your e mail.

IMAP

Internet Message Access Protocol (IMAP) servers let you work with e mail messages without downloading them to your computer first. You can preview, delete, and organize messages directly on the e mail server, and copies are stored on the server until you choose to delete them. IMAP is commonly used for business e mail accounts.

Default Ports

  • SMTP AUTH: Port 25 or 587 (some ISPs are blocking port 25)
  • SMTP StartTLS Port 587
  • SMTP SSL Port 465
  • POP Port 110
  • POP SSL Port 995
  • IMAP Port 143
  • IMAP SSL Port 993
  • IMAP StartTLS Port 143

The following list of SMTP, POP3, and IMAP server should help you if you don’t know what mail server you should use for your mail account.

  SMTP POP3 IMAP
Gmail smtp.gmail.com pop.gmail.com imap.gmail.com
  SSL Port 465 SSL Port 995 SSL Port 993
  StartTLS Port 587
TLS/SSL encryption required: yes
Please make sure, that POP3 access is enabled in the account settings. Login to your account and enable POP3. Please make sure, that IMAP access is enabled in the account settings. Login to your account and enable IMAP.
Outlook.com smtp.live.com pop3.live.com imap.mail.yahoo.com
  StartTLS Port 587 SSL Port 995 SSL Port 993
  TLS/SSL encryption required: yes TLS/SSL encryption required: yes  
Yahoo Mail smtp.mail.yahoo.com pop.mail.yahoo.com  
  SSL Port 465 SSL Port 995  
Yahoo Mail Plus plus.smtp.mail.yahoo.com plus.pop.mail.yahoo.com plus.imap.mail.yahoo.com
  SSL Port 465 SSL Port 995 SSL Port 993
Yahoo UK smtp.mail.yahoo.co.uk pop.mail.yahoo.co.uk imap.mail.yahoo.co.uk
  SSL Port 465 SSL Port 995 SSL Port 993
Yahoo Deutschland smtp.mail.yahoo.de pop.mail.yahoo.de imap.mail.yahoo.de
  SSL Port 465 SSL Port 995 SSL Port 993
Yahoo AU/NZ smtp.mail.yahoo.com.au pop.mail.yahoo.com.au imap.mail.yahoo.com.au
  SSL Port 465 SSL Port 995 SSL Port 993
Windows Live (Hotmail) smtp.live.com pop3.live.com  
  StartTLS Port 587 SSL Port 995  

JavaScript Frameworks and Resources

0

Knockout.js

Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model. Any time you have sections of UI that update dynamically (e.g., changing depending on the user’s actions or when an external data source changes), KO can help you implement it more simply and maintainably.
http://knockoutjs.com/
Knockout.js

Angular.js

AngularJS is an open-source JavaScript framework, maintained by Google, that assists with running what are known as single-page applications. Its goal is to augment browser-based applications with model–view–controller (MVC) capability, in an effort to make both development and testing easier. The library reads in HTML that contains additional custom tag attributes; it then obeys the directives in those custom attributes, and binds input or output parts of the page to a model represented by standard JavaScript variables. The values of those JavaScript variables can be manually set, or retrieved from static or dynamic JSON resources.
http://angularjs.org/
Angular.js

Backbone.js

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
http://backbonejs.org
Backbone.js

Node.js

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
http://nodejs.org/
Node.js

Modernizr

Modernizr is a small JavaScript library that detects the availability of native implementations for next-generation web technologies, i.e. features that stem from the HTML5 and CSS3 specifications. Many of these features are already implemented in at least one major browser (most of them in two or more), and what Modernizr does is, very simply, tell you whether the current browser has this feature natively implemented or not.
http://modernizr.com
Modernizr

Require.js

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.
http://requirejs.org
Require.js

Less

LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.LESS runs on both the server-side (with Node.js and Rhino) or client-side (modern browsers only).
http://lesscss.org/
Less

Sass

Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.
http://sass-lang.com
Saas

HTML5 Cheat Sheet

0

HTML5 Cheat Sheet – Tags

HTML5 Cheat Sheet - Tags

HTML5 Cheat Sheet By InMotion Hosting – A Virtual Private Servers Provider

HTML5 Cheat Sheet – Event Handler Attributes

HTML5 Cheat Sheet - Event Handler Attributes

HTML5 Cheat Sheet By InMotion Hosting – A Web Hosting Provider

HTML5 Cheat Sheet – Browser Support

HTML5 Cheat Sheet - Browser Support

HTML5 Cheat Sheet By InMotion Hosting – A Dedicated Server Provider