How to decode HTML entities using jQuery?

Decoding of HTML entities encoded string will be required specially during the AJAX operation. During AJAX operation, if we get HTML entities encoded string, it is required to be decoded before displayed to users. If you want to display HTML entities encoded string in textarea, then you can use following code,

var decode = $('<textarea/>').html(encoded).val();

If you want to display HTML entities encoded string in div, then you can use following code,

var decode = $('<div/>').html(encoded).text();

 

SPF Record & Outgoing mails

SPF record is used to accurately calculate the reputations of envelope-sender domains and mailservers by mailbox-providers. It works as follows: If many users flag emails as spam from example.com, then SPF allows the mailbox-provider to more accurately say that, “examplea.com is a spammer”, because the SPF record of example.com is used to identify it as a spam. Conversely, if any user flag spoofed email as spam from example.com, then SPF allows the mailbox-providers to maintain the good reputation for example.com and makes the email flow normal. So, we should always use SPF to make spam filtering more accurate.

SPF record is used to accurately calculate the reputations of envelope-sender domains and mailservers by mailbox-providers. It works as follows: If many users flag emails as spam from example.com, then SPF allows the mailbox-provider to more accurately say that, “example.com is a spammer”, because the SPF record of example.com is used to identify it as a spam. Conversely, if any user flag spoofed email as spam from example.com, then SPF allows the mailbox-providers to maintain the good reputation for example.com and makes the email flow normal. So, we should always use SPF to make spam filtering more accurate.

As a PHP developer, everyone familiars with the PHP mail (http://php.net/manual/en/function.mail.php) function, which is used for sending emails. But, one can’t send email using SMTP authentication using this mail function. This makes most outgoing emails caught by spam-filters because of the SPF (Sender Policy Framework) check.

An important thing about SPF is that, it only performs checks on the envelope sender (Return-Path header), not on the user-visible from header. You can read about this at http://www.openspf.org/FAQ/Envelope_from_scope.

In most of the application, we use PHP’s mail function. If we check the outgoing mail header sent using the mail function, we can see that the envelope sender (Return-Path header) is a common address of the server or localhost even if you provide the From header of your domain to the mail.

So, when SPF checks performed by mailserver, it checks only the envelope sender which is a common address of the server or localhost and ignoring the from address, which is a genuine email address of the domain. So, our SPF record will be ignored. And, the server may not have an SPF record. In such case mail server detect a softfail. If you notice in Gmail, it identifies such softfail with phrase “best guess record”. Gmail uses a heuristic system to create best-guess SPF records for domains that don’t use SPF. For more details, go to http://www.ceas.cc/2006/19.pdf

As Gmail is using a best-guess records for server/domains that don’t have an SPF record, this guess is sometimes wrong, which cause a softfail. If your mail is being routed through a new mailserver, which may not add to the best-guess SPF records by Gmail, then we can see the softfail disappear after a while.

There is some basic solution to avoid softfails due to SPF record.

One solution would be to use SMTP mailer instead of PHP’s simple mail function. There are many SMTP mailer classes available free, like PHPMailer. SMTP mailer is directly talking to the mail server, so it can set the envelope-sender to be same as the From address. You can also specify the envelope-sender while using SMTP mailer.

Alternatively, we can also use Google’s SMTP (smtp.google.com) to send outgoing mails using Google’s username and password. In this case, we have to simplify our SPF record to identify Google by adding “include:_spf.google.com ~all”.

But, if we have already used a PHP’s mail function throughout the application, and switching to SMTP mailer requires so much time and effort, we can still set an envelope-sender using PHP’s mail function. To set the envelope-sender, use sendmail’s -f/-F command as a fifth additional-options parameter of the PHP’s mail function.

PHP Code:

mail("user@example.com",  "test subject",  "test message",  $headers,  "-F 'Example  Envelope-sender' -f returnpath@example.com");

We can use any of domain email addresses or from address instead of returnpath@example.com in the above code snippet.

There may be other solutions to achieve this. The key is to set the envelope-sender (Return-Path) to the email address of the domain.

vi Editor: UNIX

vi is a command-line text editor originally created for the Unix operating system.

The name vi is derived from the shortest unambiguous abbreviation for the command visual; the command in question switches the line editor ex to visual mode.

Most of the network administrators are familiar with this little editor in Unix, because they use it regularly. But, for first timers, it’s most difficult editor. First timers have to remember all commands and keys to edit a simple file.

vi has two modes, Insert mode and Command mode. In insert mode, you can add/edit the texts in file. And in command mode, you can navigate and command the editor like save, exit, copy, paste, etc.

These are the commands and keys for those who want to get familiar with vi editor.

Command to open the vi editor:

vi filename

This command creates a new file if filename is not available in current directory. By default, vi begins in command mode.

To start the insert mode, you can use following keys:

Insert text at beginning of line:

I

Insert text at cursor:

i

append text after cursor:

a

Append text at line end:

A

Open line above cursor:

O

Open line below cursor:

o

To switching back, and start the Command mode, press [ESC]

Most commands execute as soon as typed except for “colon” commands which execute when you press the return key.

For cursor movement in command mode, you can use following commands/keys:

Go to beginning of line

0

Go to end of line

$

Go to line number ##

:##

Go to line n

nG

Go to last line

G

Left 6 chars

6h

Move left, down, up, right

h j k l

Move left, down, up, right

← ↓ ↑ →

Scroll Backward 1 screen

[ctrl] b

Scroll Forward 1 screen

[ctrl] f

Scroll by sentence forward/backward

( )

Scroll by word forward/backward

w b

Scroll by paragraph forward/backward

{ }

Scroll Up 1/2 screen

[ctrl] u

Scroll Down 1/2 screen

[ctrl] d

For deleting/changing text/character in command mode, you can use following commands/keys:

Change word

cw

Replace one character

r

Delete word

dw

Delete text at cursor

x

Delete entire line (to buffer)

dd

Delete (backspace) text at cursor

X

Delete 5 lines (to buffer)

5dd

Delete current to end of line

D

Delete lines 5-10

:5,10d

For editing content in command mode, you can use following commands/keys:

Copy line

yy

Copy n lines

nyy

Copy lines1-2 /paste after 3

:1,2t3

Move lines 4-5/paste after 6

:4,5m6

Paste above current line

P

Paste below current line

p

Undo all changes to line

U

Undo previous command

u

Join previous line

J

Find next string occurrence

n

Search backward for string

?string

Search forward forstring

/string

% (entire file) s (search and replace) /old text with new/ c (confirm) g (global – all)

:%s/oldstring/newstring/cg

Ignore case during search

:set ic

Repeat last command

.

For saving and quiting in command mode, you can use following commands/keys:

Save changes to buffer

:w

Save changes and quit vi

zz or :wq

Save file to new file

:w file

Quit without saving

:q!

Save lines to new file

:10,15w file

In all of the above commands, a number n will tell vi to repeat that command n times.

:syntax on Turn on syntax highlighting
:syntax off Turn off syntax highlighting
:set number Turn on Line numbering (shorthand :set nu)
:set nonumber Turn off Line numbering (shorthand :set nonu)

:set ignorecase Ignore case sensitivity when searching
:set noignorecase Restore case sensitivity (default)

Pencil Project – An open-source GUI prototyping tool

Pencil Project, a free, open-source, cross-platform GUI prototyping tool, that people can easily install and use to create mock-ups in popular desktop platforms. Pencil is available as a standalone application and a Firefox extension.

Pencil Project, a free, open-source, cross-platform GUI prototyping tool, that people can easily install and use to create mock-ups in popular desktop platforms. Pencil is available as a standalone application and a Firefox extension. You can download it from here.

Pencil provides various built-in shapes collections by default, which includes flowchart elements, desktop/web UI elements, Android/iOS GUI shapes and general purpose shapes for drawing different types of user interface ranging from desktop to mobile platforms. There are also many other freely distributed collections on the internet provided by the community, which can easily installable to Pencil with simple drag-and-drop operation.

Pencil has pre-installed stencils for Android and iOS UI, which makes it even easier and faster to start prototyping apps with a simple installation. These stencils are included from version 2.0.2. Some of the stencil collections that you can try are collected in the download archive.

Drawing diagrams are as easy as UI design in pencil, because of its collection of flowchart shapes. Pencil also supports connectors used for “wire” shapes in the diagram.

Pencil provides a clipart browser tool integrated with OpenClipart.org to let users easily find cliparts and add them into the drawing by simply drag-and-drop. These cliparts are in vector format, which are easily scalable to appropriate sizes.

Pencil can export drawings into most of the popular formats including OpenOffice/LibreOffice, Image formats (JPG, GIF, PNG), text documents, Inkscape SVG, Adobe PDF and HTML page that can deliver to viewers.

For the web UI, Pencil provides links of an element to specific page in the same document. These links are converted to hyperlinks when the document is exported into HTML pages. This helps the user to understand the UI flow of an application mockups.

For more information about the pencil project, click here.
Firefox extension can be downloaded from here.

MySQL database difference with MySQL Workbench

MySQL Workbench is one of the best tools to manage databases. You can connect multiple databases and query each database separately. And most importantly, it also synchronizes and find difference of online as well as offline database. In both cases, you have to manage models of offline database.

mysql-workbenchAs a DB Manager, there is always a need for database synchronization or difference tool to upload the latest changes to the server.

For uploading latest files, there are so many tools freely available like SVN. But when there is a time to upload the database changes, there are very few options available for free. MySQL Workbench is one of the free tools provided by Oracle which provides database synchronization as well as database difference facility.

MySQL Workbench is one of the best tools to manage databases. You can connect multiple databases and query each database separately. And most importantly, it also synchronizes and find difference of online as well as offline database. In both cases, you have to manage models of offline database.

It is a unified visual tool which provides data modeling, SQL development, and comprehensive administration tools for server configuration, user administration, and much more. MySQL Workbench is available for free on Windows, Linux and Mac OS.

MySQL Workbench is used to visually design, model, generate, and manage databases, which includes creating complex ER models, forward and reverse engineering. It also delivers visual tools for creating, executing, and optimizing SQL queries. SQL editor of MySQL Workbench provides color.

MySQL Workbench also delivers key features like performing difficult change management and documentation tasks, which normally requires much time and effort.

New version of MySQL Workbench also provide database migration from popular database servers to MySQL, which includes Microsoft SQL Server, Sybase ASE, PostreSQL, and other RDBMS. It’s easy to use solution for migrating can migrate tables, objects and data to MySQL to quickly and easily convert existing applications to run on windows and other platforms.

For more information about MySQL Workbench, visit http://www.mysql.com/products/workbench/
MySQL Workbench is freely available at http://www.mysql.com/downloads/workbench/.