What is Internationalization and localization?

One of the best way to reach larger audience across the globe is to have your applications in multiple languages. It is essential to understand some terminology.

What is Internationalization?
Internationalization refers to the ability of an application to be localized.

What is Localization?
The term localization refers to the adaptation of an application to meet specific language (or culture) requirements.

Abbreviations i18n & l10n

Internationalization and localization are often abbreviated as i18n and l10n respectively; 18 and 10 are the number of characters between the first and last character.

An application which supports multiple language is known as “multilingual software”. Today most of the 3rd generation websites are i18n while making itself.

Permanent link to this article: https://blog.openshell.in/2013/12/what-is-internationalization-and-localization/

How to remove special characters using jQuery ?

jQuery code can be used to remove special characters.

[js]
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#input_field_name").keyup(function(event)
{
original_val = jQuery("#input_field_name").val();
rep_value = name.replace(/[^a-zA-Z 0-9.]+/g,”);
jQuery("#input_field_name").val(rep_value);
});
});
</script>
[/js]

Permanent link to this article: https://blog.openshell.in/2013/12/how-to-remove-special-characters-using-jquery/

Submitting a form using jQuery AJAX

HTML form, that’s to be submitted by jQuery AJAX.

[html]
<form id=”employee” action=”employee.php” method=”POST” name=”contact”>
<div>Name: <input id=”name” type=”text” name=”name” size=”30″ value=”" /></div>
<div>Email: <input id=”email” type=”text” name=”email” size=”30″ value=”" /></div>
<div>Phone: <input id=”phone” type=”text” name=”phone” size=”30″ value=”" /></div>
<div><input id=”submit_btn” type=”submit” name=”submit” value=”Send” /></div>
</form>
<div id=”result”></div>
[/html]

Java Script code using jQuery AJAX

[js]

<script type=”text/javascript”>
$(document).ready(function() {
$("form").submit(function() {
var frm = $(‘#employee’);
$.ajax({
type: frm.attr(‘method’),
url: ‘/employee.php’,
data: frm.(serialize),
success: function (data) {
alert(‘Submitted’);
$(‘#result’).html(data);
},
error: function(jqXHR, textStatus, )errorThrown{
// log the error to the console
console.log(
"The following error occured: "+
textStatus, errorThrown
);
}
});
return false;
});
});
</script>
[/js]

Permanent link to this article: https://blog.openshell.in/2013/12/submit-form-using-jquery-ajax/

Dynamically create form in javascript on fly

To create a form dynamically using JavaScript on fly of the webpage. This which helps to create form and input controls dynamically.

[javascript]

/* To create form with javascript */

var form = document.createElement("form");
form.setAttribute(‘method’,"post"); // form method
form.setAttribute(‘action’,"test.php"); // form action url
form.setAttribute(‘name’,"frmName"); // form name
form.setAttribute(‘id’,"frmId"); // form ID
form.setAttribute(‘target’,"_blank"); // form target location

/* To create input control with javascript */
var inputCtrl = document.createElement("input");
inputCtrl.type = "hidden"; // input control type
inputCtrl.name = "data"; // input control name
inputCtrl.value = "test"; // input control value

/* To bind created input control with created from */
form.appendChild(inputCtrl);

/* To bind created form with current document body */
document.body.appendChild(form);

/* Now you can submit created form */
form.submit();

[/javascript]

Permanent link to this article: https://blog.openshell.in/2013/12/dynamically-create-form-in-javascript-on-fly/

How to use serialized object in Active Record using Rails?

Serializing Object Will help us to store multiple column values in single Database column and even making processing using that column simple. It helps to extended the table without adding new column in table. Because we can store multiple column values in single column as Hash value.

So, It reduce the difficulty of retriving and storing datas into the database. Here I have given some guidelines to implement serializing data’s using our rails application

[sql]
— In Sql Query creating new table called users
CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `user_name` varchar(255), `group_id` int(11), `is_active` tinyint(1), `preferences` text, `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
[/sql]

[ruby]
# in model, setting preference column as serializable object
class Utility < ActiveRecord::Base
serialize :preferences
end
[/ruby]

[ruby]
# Storing values in serializable object
user = User.new
user.preferences = {:account_locked => true, :password_failed_attempt => 2, :time_zone => "IST",…}
user.save
[/ruby]

[ruby]
# Retriving value from the serializable object
user = User.find(1)
user.preferences # => {:account_locked => true, :password_failed_attempt => 2, :time_zone => "IST",…}
user.preferences[:account_locked] # => true
user.preferences[:password_failed_attempt] # => 2
user.preferences[:time_zone] # => "IST"
[/ruby]

Permanent link to this article: https://blog.openshell.in/2013/11/how-to-use-serialized-object-in-active-record-using-rails/

Way2SMS API – INFRINGEMENT NOTICE

Dear Way2sms API Followers, Recently I have received “INFRINGEMENT NOTICE” from Way2SMS for providing API. I have attached that mail content for your reference. So, that I cannot support you guys on future. Thanks for using this blog.

————————————————————————————————————–

Dear Respondent,

Without prejudice, this is with reference to the illegal APIs.

We, M/s Way2online Interactive India Private Limited an Information Technology Company, which owns http://way2sms.com andhttp://www.160by2.com and other websites as well (hereinafter referred as to way2sms and 160by2 or websites), which promotes Way2online Interactive India’s wireless products and services. We offer free SMS service to our registered users throughhttp://way2sms.com andhttp://www.160by2.com, whereby the users can communicate information to their known persons. The above said websites act as a venue, which allows to its registered users to communicate information, at any time, from anywhere, within India and overseas. The name in itself is much respected and known for its high quality of service in its domain. We claims the ownership of all the Intellectual Property Rights vested in way2sms and 160by2 including all patents, trademarks, copyrights, goodwill, rights of publicity, trade secrets and other rights.

It is observed that, your illegal APIs provide a means to bypass measures that effectively control access to our protected work, and allow registered users of www.way2sms.com & www.160by2.com to send sms through the said apps using www.Way2SMS.com & www.160by2.com SMS gateways.

1. http://thaangaraj.blogspot.in/

2. https://blog.openshell.in/author/thangaraj/

As a first step of our legal action, we would request you to initiate required measures to terminate complete access to the said illegal APIs and other such access to connect through www.way2sms.com and www.160by2.com with immediate effect.

If you refuse to honor our request or if you continue to do infringement, you are liable for all the damage claims including and not limited to financial, brand identity, reputation, copyright, trademark, any rights and remedies available to the company.

Further submitted that you are liable for committing identity theft, cheating by personation and the said offences as punishable under Sections 65, 66, 66-C and 66-D of the Information Technology Act, 2000.

Further, you are liable for committing these deceptive acts which also constitute the offence punishable as Cheating, Cheating by personation, Mischief, Forgery, Making a false electronic document, Forgery for the purpose of cheating, Forgery for the purpose of harming reputation, Using as genuine a forged document or electronic record, Having possession of document knowing it to be forged and intending to use it as genuine, the offences as punishable under Section 417, 419, 426, 464, 465, 468, 469, 471, 474 and read with section 120- B of the Indian Penal Code, 1860.

Permanent link to this article: https://blog.openshell.in/2013/11/way2sms-api-infringement-notice/

Stripe Payment Gateway Implementation

Stripe Payment Gateway Implementation:

Steps to Implement:

  1. Download the stripe package(stripe).
  2. Extract that into the web accessible folder.
  3. Create an account in stripe using this url: https://manage.stripe.com/login
  4. After Created the account get the test secret key and test publishable key from your stripe account using this url: https://manage.stripe.com/account/apikeys
  5. Now in config.php file change the “testSecretKey” and “testPublishableKey” string with your stripe secret_key and publishable_key.
  6. Now Navigate to http://localhost/stripe and enter the details in that form.

For Example:
Email Address : xxx@gmail.com
Card Number   : 4242424242424242(For Sample Card Number Please Visit the following link: https://stripe.com/docs/testing ).
CVC    Number    : 000 (It is a secret three digit number which is avilable in backside of the card).
Amount        : 3(it is in USD dollars).
Expiration     : 11/14 (expiration date of the card.For Testing purpose always give the future date.)

Now Hit submit.

Now, sign in to your stripe account and you can see the transaction you made using the sample stripe form.
Thats it !!! Easy Job ,but Great Job.

Permanent link to this article: https://blog.openshell.in/2013/10/stripe-payment-gateway-implementation/

Yii & google map integration

Now the yii and google map integration become easy with this super extension JQUERY-MAP.

Extension url : http://www.yiiframework.com/extension/jquery-gmap/

Permanent link to this article: https://blog.openshell.in/2013/10/yii-google-map-integration/

YII Upload the file to FTP server

The below function used to upload the local file to remote directory.

[php]
/**
* Upload the file in ftp directory
* @param string $localFilePath
* @param string $remoteFilePath .
* @return boolean
*/
public function CopyFileToFtpBucketDir($localFilePath, $remoteFilePath)
{
<strong><em>//Credential are configured in main.php</em></strong>
$ftpSource = Yii::app()-&gt;params[‘ftpSource’];
$ftpUserName = Yii::app()-&gt;params[‘ftpUserName’];
$ftpPassword = Yii::app()-&gt;params[‘ftpPassword’];
<em><strong>// set up basic connection</strong></em>
$connect = ftp_connect($ftpSource);
if (!$connect)
{
Yii::log(‘ftp is not connected’, CLogger::LEVEL_ERROR, ‘some string to identify.’ . strstr(str_replace(‘/’, ‘.’, __DIR__), ‘some string to identify’) . ‘.’ . __METHOD__);
exit;
}
else
{
Yii::log(“Login with username and password”, CLogger::LEVEL_ERROR, ‘some string to identify.’ . strstr(str_replace(‘/’, ‘.’, __DIR__), ‘some string to identify’) . ‘.’ . __METHOD__);
$loginResult = ftp_login($connect, $ftpUserName, $ftpPassword);
<em><strong>// upload a file</strong></em>
if (ftp_put($connect, $remoteFilePath, $localFilePath, FTP_ASCII))
{
Yii::log(“Successfully uploaded $remoteFilePath\n”, CLogger::LEVEL_ERROR, ‘some string to identify.’ . strstr(str_replace(‘/’, ‘.’, __DIR__), ‘some string to identify’) . ‘.’ . __METHOD__);
$return = true;
}
else
{
Yii::log(“There was a problem while uploading $remoteFilePath\n”, CLogger::LEVEL_ERROR, ‘some string to identify.’ . strstr(str_replace(‘/’, ‘.’, __DIR__), ‘some string to identify’) . ‘.’ . __METHOD__);
$return = false;
}
<em><strong>// close the connection</strong></em>
ftp_close($connect);
return $return;
}
}
[/php]

Permanent link to this article: https://blog.openshell.in/2013/10/yii-upload-the-file-to-ftp-server/

How to retrieve the last record in each group using mysql

In single SQL query itself we can retrieve the last record in each group. It will help us to perform action better, faster and simpler. In this post I will explain about you how to do it.

Here is my table structure for your reference.

[sql]
desc post_status;
+—————-+————-+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+—————-+————-+——+—–+———+—————-+
| post_status_id | int(11) | NO | PRI | NULL | auto_increment |
| post_id | int(11) | NO | | NULL | |
| status | varchar(25) | NO | | NULL | |
+—————-+————-+——+—–+———+—————-+
[/sql]

According to this table, It contains multiple status for single post.

[sql]
SELECT * FROM `post_status`;
+—————-+———+———-+
| post_status_id | post_id | status |
+—————-+———+———-+
| 1 | 1 | new |
| 2 | 1 | draft |
| 3 | 1 | submitted|
| 4 | 2 | new |
| 5 | 2 | draft |
| 6 | 3 | new |
| 7 | 4 | new |
| 8 | 4 | draft |
| 9 | 4 | submitted|
| 10 | 4 | updated |
+—————-+———+———-+
[/sql]

To get the last updated status of post using the following SQL Query:

[sql]
SELECT post_id, SUBSTRING_INDEX(GROUP_CONCAT(status ORDER BY post_status_id DESC),’,’,1) as status FROM `post_status` GROUP BY post_id;

+———+———-+
| post_id | status |
+———+———-+
| 1 | submitted|
| 2 | draft |
| 3 | new |
| 4 | updated |
+———+———-+
[/sql]

Explanation for the above SQL Query:

1) Grouping record by using post_id, its foreign key for post_status table.
2) Concatenate status of post using GROUP_CONCAT in descending order of post_status_id.
3) Once each post status has been concatenated, extract the first position status of post from the resultset using SUBSTRING_INDEX.
4) Now the result came, What we expected in SQL Query.

Happy Coding Guys………

Permanent link to this article: https://blog.openshell.in/2013/10/how-to-retrieve-the-last-record-in-each-group-using-mysql/