Farrukh Malik

December 29, 2017

SPF, DKIM, DMARC Related Configuration for Google Apps Account

Configure SPF records Create a TXT record containing this text: v=spf1 include:_spf.google.com ~all. If you are sending email from your server (e.g. a web application sending emails through postfix server configured on your cloud), you need to add it’s IP address […]
March 3, 2016

Start Mongodb after System Crash

Recently, I experienced that Mongodb was not starting after a system crash. When I ran service mongod restart mongodb crashed with error in log file. The error said "exception in initAndListen: 12596 old lock file, terminating" If you ever encounter […]
September 4, 2015

Ubuntu – “node: No such file or directory” error on using express-generator

Issue: After you install express-generator on your Ubuntu machine and try to run it like express -h You may encounter an error saying "/usr/bin/env: node: No such file or directory" Solution: The issue is that the Node executable for Ubuntu is […]
June 14, 2015

Uploading multiple files with Carrierwave in Rails 4

This post shows how to use carrierwave gem to upload multiple files in Rails 4 Let suppose the following scenario. We have multiple projects and each project can have multiple screenshots. In project.rb class Project < ActiveRecord::Base has_many :screenshots accepts_nested_attributes_for :screenshots, […]
June 14, 2015

Validate a url in Rails 4

class User < ActiveRecord::Base validates_format_of :url, :with => URI::regexp(%w(http https)) end Reference: Stackoverflow 
June 14, 2015

Using has_many with Nested Form in Rails 4

This post shows how to use field_for and accepts_nested_attributes_for to created nested form for has_many model Let suppose the following scenario. We have multiple projects and each project can have multiple screenshots. Following will be the definition of model classes. class […]
April 14, 2015

Using Private key for File Transfer (SFTP)

This article is intended for the members of TeamDX. Following are the steps you need to take in order to transfer files using private key (without password) provided to you by your team lead.  Open the FileZilla client. From the top […]
April 14, 2015

Using Private key with PuTTY

This article is intended for the members of TeamDX. Following are the steps you need to take in order to log in to server using private key provided to you by your team lead.  Start PuTTY by double-clicking its executable […]
February 13, 2015

Using Twitter Bootstrap with Ruby on Rails

Step by step guide to integrate Twitter Bootstrap with Ruby on Rails application. Please note that after these steps, your application layout file will be replaced with default one. Step1: Add gem to your Gemfile gem 'twitter-bootstrap-rails' Step 2: Install required […]
January 16, 2015

Error installing debugger gem on ubuntu

I recently encountered error while bundle install. The issue was with debugger gem. Following is the error I was getting No source for ruby-1.9.3-p484 provided with debugger-ruby_core_source gem. extconf.rb failed After searching Google for answer, I found that this gem […]
January 7, 2015

500 error with rails application running in production via apache2 & passenger

I sometimes face 500 Internal Server Error when running Ruby on Rails application on Apache Passenger but the same application is working fine with webrick server. One of the following reasons are responsible for the issue. 1. Permission Issues Check […]
January 6, 2015

Eclipse gives error in generated IMarketBillingService.java file

Solution: Right Click project name, select “Properties”. Next select “Java Compiler” from the list on left and uncheck “Enable project specific settings”
April 30, 2014

Enum column in Rails

Declare an enum attribute where the values map to integers in the database, but can be queried by name. Example: class User < ActiveRecord::Base enum status: [ :admin, :user, :banned ] end  For migration, write  def up create_table :authorities do […]
April 28, 2014

Installing Apache, Ruby, MySQL, Passenger on Ubuntu 14.04

This step by step how to is intended to be a reference for those who are comfortable with working in terminals. This page lists all the commands on one place.
July 1, 2013

How to write text on existing image using php

The post below describes an easy and quick way to write text over an existing image using PHP. You can use this method to watermark your images and can put it to use in number of other ways.   First […]
June 17, 2013

How to Record Audio Files in Android

The android multimedia frameworks performs a remarkable job with recording and playing a variety of media files. By using this scalable framework you can enrich your applications with audio integration. Depending on your device hardware, you can use the MediaRecorder […]
June 3, 2013

Send SMS programmatically in Android

SMS messaging has become an integral part of every mobile phone and for the past decade every mobile device be it a smartphone or a simple mobile phone has come with an sms messaging feature. Understanding how this application works […]
May 31, 2013

How to use PDO-MySQL with PHP

PDO is a PHP extension that allows multiple PHP's database connections by creating a single cohesive interface. It allows code portability and compatibility across various platforms. It can be considered as a database access layer providing a uniform method of […]
May 29, 2013

How to use 9-Patch images in Android

Android is remarkable good in supporting various screen sizes, it allows various drawable directories for particular screens and layout configurations using density-independent pixel (dp) instructions. Android also allows using 9 patch images as backgrounds for buttons and application content. In […]
May 28, 2013

PHP PHAR Package

The phar extension is used to put entire PHP applications into a single file called a "phar" (PHP Archive) for easy distribution and installation. It provides the means for distributing code as a single archive, that does not have to […]
May 27, 2013

How to set timezone at application level and user login level using PHP

To set timezone in php at user level, you have to use the function date_default_timezone_set(). This function is available in version 5 and later of PHP   <?php date_default_timezone_set('America/Los_Angeles'); // To see a list of all supported time zones please […]
May 20, 2013

Customer Review Date Changer for Magento

The customer review date changer extension for Magento is a small, lightweight plugin that allows you to change the date for customer reviews at your Magento store. While importing your store from one CMS like WordPress to Magento, you have […]
May 16, 2013

Magento Admin Fix for CSS and JS Not Loading

After transferring the magento store to new server and database you might find that the magento admin is not loading the CSS and JS files. Because of that, the design would look out of order and the categories pages would […]
May 16, 2013

Alternate Method For Magento Incremental Update

In order to maintain all your tables and data the way it is, you often require to perform an incremental update for magento, doing it otherwise might make some of your data obsolete. Here is a simple step by step […]
May 8, 2013

SALT implementation in YII

A salt is a random data string that is used as an input to hash a password. The salt and the password are concatenated and encrypted with a cryptographic hash function and the output is then stored in the database. […]
April 19, 2013

Uploading Extension to MagentoConnect: Invalid Package Name

While uploading to magento connect, we often receive an error “Invalid Pakage Name- the Package name without ext should be ……..”. We have to take care of few things while packaging and uploading extension to magento connect. Following is the […]
April 12, 2013

Multiple Attachments using PHPMailer Class

  To send an email with multiple attachments using php, we would be using a class PHPMailer. You can download that class from this link: http://phpmailer.worxware.com/index.php?pg=sf&p=dl To add more than one attachments to our email we would be using the […]
April 10, 2013

How to use BB code with PHP

  What is BB code? Bulletin Bar Code or simply BB Code is a lightweight markup language that is used to impose strict formatting rules in discussion boards, forums and occasionally in blogs. Its main objective is to facilitate a […]
April 9, 2013

Nonce Implementation in PHP

What is Nonce? Literally it means a number that can be used only once. Nonce is often a random or pseudo random number that is used in authentication protocols in preventing semantic URL and replay attacks using old communications. Each […]
November 28, 2012

Website Security Measures

I would like to share my personal observations and knowledge relating website security. You can add more by commenting this post. Password Hashing Passwords and other credentials must be stored hashed in Database. Use md5() or sha1() functions. Password Renew […]
November 28, 2012

Toggle WiFi Method in Android

First you need to have user permissions to access WiFi state and change it. To do so add following XML nodes in your app’s Manifest XML file under root node. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> Next we need to […]
November 28, 2012

Verify HTTP URL with PHP

Developers often require verifying the URLs of external sites in various situations like for Affiliate Program, Link Building and many more. We can create a simple function named verifyURL()  which accepts the URL as string parameter and return Boolean if […]
May 19, 2012

How to add custom title bar to android application

There are multiple ways to customize title bar in android application. Today, I am going to show a way in which we’ll completely change the looks of title bar and add extra views to it.
April 24, 2012

Return values to Activity from widgets in PopupWindow

You may face certain scenario where you want to input single value from user and that value is not simple text. let’s say you want to display a custom widget. In such cases, instead of creating a new activity or […]
April 23, 2012

Code to make android phone silent

You can use the setRingerMode() method of AudioManager class.  AudioManager audiomanage = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audiomanage.setRingerMode(AudioManager.RINGER_MODE_SILENT);  The value that you pass to the method should be one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE Also note that you have to add following permission to […]
December 9, 2011

How to Restart Ruby on Rails Applications?

If you are running Ruby on Rails application (e.g Redmine) using Apache & Phusion Passenger and need to be restart your application, then you simply have to create a blank text file with name restart.txt in the tmp directory of […]
November 18, 2011

Protect Magento Product Images from getting Stolen

It is good that magneto offers watermarking for securing the catalog/product images but this security is not sufficient for advance internet users. Suppose, following is the link for your watermarked image http://www.yourwebsite.com/media/catalog/product/cache/1/image/de684549e4151748e56ee0dd7902c19f/m/y/my-first-image.jpg But if anyone removes the cache/1/image/de684549e4151748e56ee0dd7902c19f part of […]
September 24, 2011

Magento Admin URL Error 404 Fix

After moving Magento site to new server/location we often get "Error: 404 Not Found" while accessing the admin / back-end. The reason of this error is store_id and website_id should be set to "0" (zero). For some reason when you […]
August 14, 2011

Magento Google Checkout 401 Failed to Get Basic Authentication Headers

If you are struggeling to integrate the google checkout with Magento and facing the following error in google checkout console  We encountered an error trying to access your server at https://yourdomain.com/googlecheckout/api -- the error we got is Send failed with […]
June 18, 2011

Enable In-place Editing in Yii Grid

Today someone asked me for help to integrate Jeditable with Yii CGridView. So I thought why not write a little tutorial that can help others as well. In this article I assume that you are comfortable working with Yii; you […]
June 8, 2011

How to create custom validation rule

In the scenarios where validation rules provided by the Yii framework won’t handle your requirements, you can create custom validation rules. One example is the "authenticate" validation rule provided in "LoginForm" model of Yii blog demo. You can create your […]
May 15, 2011

Upgrade Redmine

Login to your server using putty Go to RubyForge and copy the URL of Redmine version you want to upgrade to. Download it to your server using wget command. Go to Redmine Site to check the requirements. Make sure you […]
May 15, 2011

Install RubyGems from Source

If you want to install some previous version of RubyGem or for what ever reason, want to install RubyGem from source, perform following steps Login to your server using putty Go to RubyForge and copy the URL of RubyGem of […]
May 15, 2011

How to remove/uninstall RubyGem from your system

If you installed rubygem with some sore of package management system, it probably provides for an uninstall capability. If not, here is one way to remove it. Find out where ruby installs its libraries. If you don’t know where your […]
May 15, 2011

How to Freeze Gems with recent versions of Rails

If you want to freeze the gems under vendor/gems, just run the following command in your application directory   rake gems:unpack  
May 12, 2011

Constructor Overloading in PHP

There is no simple method of overloading constructors in PHP. There are few workarounds to achieve this. I use the following technique. class UserIdentity extends CUserIdentity { public function __construct() { $arg_list = func_get_args(); switch(func_num_args()) { case 1: // calling […]
April 26, 2011

Yii’s default validator Aliases

Below is the complete list of predefined validator aliases: boolean: alias of CBooleanValidator, ensuring the attribute has a value that is either CBooleanValidator::trueValue or CBooleanValidator::falseValue. captcha: alias of CCaptchaValidator, ensuring the attribute is equal to the verification code displayed in […]
April 12, 2011

Specifying nested relations for eager loading

Eager loading can be nested. For example, if for every comment, we also want to know its author, we could use the following ‘with’ find:   // find all posts together with their author and the author's profile Post::model()->with('author','author.profile')->findAll();  
April 12, 2011

Replace text box with drop down list in filter of CGridView

By default, Yii displays a textbox to search (filter) within results/records displayed by CGridView. In order to change those textboxes to drop down list (combo boxes), all you need to do is to assign an array to "filter" property of […]
April 10, 2011

Remove/Uninstall all gems

gem list | cut -d" " -f1 | xargs gem uninstall -aIx   Source: http://geekystuff.net/2009/1/14/remove-all-ruby-gems
April 9, 2011

Add conditions in search for relational tables

Let’s discuss example relationship given on following URL http://www.yiiframework.com/doc/guide/1.1/en/database.arr If you want to be able to filter results in grid using Posts’ author name then modify the search function of  Post model to similar to the one given below.
April 6, 2011

Change CGridView CSS file for entire application

To use your custom css file globally, set the cssfile property in config file   'components'=>array( 'widgetFactory'=>array( 'widgets' => array ( 'cssFile' => '/css/style-gridview.css', ) ), );  
April 4, 2011

Target IE6, IE7, IE8 uniquely

Note: It’s generally considered to be a bad practice to include hacks within your stylesheets, there are some scenarios where you can use these hacks e.g. if you have only one style that needs to be handled differently.
April 3, 2011

CSS 3 Shadows

April 3, 2011

Accessing modules method in Yii

Yii::app()->getModule('user')->encrypting($this->password)  or Yii::app()->controller->module->encrypting($this->password)  
April 3, 2011

Check for Ajax’ed request in Yii

if( Yii::app()->request->isAjaxRequest) {     // do some thing…. }
April 3, 2011

Session Handling in Yii

Yii::app()->session->add(‘product’, $productId); Yii::app()->session->get(‘product’); Yii::app()->session->remove(‘product’);
April 3, 2011

Send & retrieve cookies in Yii

To retrieve a cookie with the specified name: $cookie=Yii::app()->request->cookies[$name]; $value=$cookie->value;   To send a cookie:  $cookie=new CHttpCookie($name,$value); Yii::app()->request->cookies[$name]=$cookie;
April 3, 2011

Get & Set current language in Yii

To get current language:  $lang = Yii::app()->language;   To set current language: Yii::app()->language = ‘en’;
April 3, 2011

Get current Controller & action in Yii

 In view file  $this->uniqueid        (controller name) $this->action->Id      (action name) ($this is CController instance) In other files Yii::app()->controller->id  Yii::app()->controller->action->id
April 3, 2011

Get Id of an active form element in Yii

March 25, 2011

CAutocomplete to display one value and submit another

  Source: http://www.yiiframework.com/wiki/25/using-cautocomplete-to-display-one-value-and-submit-another/ Don’t forget to use the attached Javascript and CSS files. This code does not work with jQuery UI auto complete. Javascript File CSS File
March 24, 2011

Create Symbolic links in Windows 7

 To create symbolic link in windows 7, use command mklink. C:Windowssystem32> mklink Creates a symbolic link. MKLINK [[/D] | [/H] | [/J]] Link Target /D Creates a directory symbolic link. Default is a file symbolic link. /H Creates a hard […]
February 14, 2011

Run a Command as Administrator from the Windows 7 / Vista

 To try this out, go to the run box and type in something (cmd, for example) Now instead of hitting the Enter key, use Ctrl+Shift + Enter. You will be prompted with the obnoxious User Account Control dialog… but it […]
February 14, 2011

Installing Self-Signed SSL Certificate on WAMP Server

 Part I: Creating SSL Certificate 1- download windows executable file for openssl from http://slproweb.com/products/Win32OpenSSL.html and install it 2- open cmd window  3- cd to [openssl installation directory]/bin e.g if your installation directory is C:Program FilesOpenSSl, then cd to C:Program FilesOpenSSlbin 3- type […]
February 7, 2011

Customize CKEditor

 To add a new font in CKEditor’s font drop down list, add the following lines of code in your config.js   CKEDITOR.editorConfig = function( config ) { config.font_names ="Futura;" + config.font_names; }; CKEDITOR.on( 'instanceCreated', function( e ){ e.editor.addCss("@font-face{font-family:'Futura'; src:url('http://www.your-url.com/font/Futura_Medium.ttf');" ); […]
February 4, 2011

Debug JavaScript in Internet Explorer

Source: http://www.jonathanboutelle.com/how-to-debug-javascript-in-internet-explorer Microsoft Office 2007: The Microsoft Script Editor is normally installed by default with Office 2007, but is not reachable directly from the Start -> All Programs -> Microsoft Office menu.  Instead, you can usually find it by searching for […]
January 20, 2011

Using Join in Update Query

  update solvents,Answers left join solvents.`Solvent` on Answer set t.`Answer_ID` = Answers.Answer_ID where Answers.Question_ID = 2;  
December 17, 2010

Error in Wamp Server Configuration File after updating PHP to PHP 5.3.1

Problem: When you update PHP to version PHP 5.3.1 using WAMP PHP Addons and restart WAMP, you’ll start getting the following error. The configuration file contains a syntax error on line 863:  [EParseError] Invalid section tag    This error refers […]
December 15, 2010

MySql query – Grouping by first character in field value

MySQL select statement for querying records grouped by first character of value SELECT case when SUBSTRING( UPPER(`title`) from 1 for 1) between '0' and '9' then '0-9' else SUBSTRING( UPPER(`title`) from 1 for 1) end as letter, count(title) AS occurences […]
December 2, 2010

Hexadecimal codes of Colors

The 16 named colors   black white red green blue cyan magenta yellow gray silver maroon olive navy teal purple lime black white red green blue cyan magenta yellow gray silver maroon olive teal teal purple lime    
November 28, 2010

iFrame in jQuery UI Dialog

To display iFrame in jQuery UI Dialog, use the following code. <html> <head> <link rel="stylesheet" href="./styles/smoothness/jquery-ui-1.7.2.custom.css" type="text/css" media="screen" /> <script type="text/javascript" src="./scripts/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="./scripts/jquery-ui-1.7.2.custom.min.js"></script> <script type="text/javascript"> $(function() { $('a').click(function(e) { e.preventDefault(); var $this = $(this); var horizontalPadding = 30; […]
November 9, 2010

Make the Footer Stick to the Bottom of a Page

Step 1: Markup   <html> <head><!-- header includes... --></head> <body> <div class="wrap"> <div class="header"></div> <div class="middle"></div> </div> <div class="footer"> <!-- footer contents ... --> </div> </body> </html>   Step 2: CSS   html,body{height:100%;} .wrap {min-height: 100%;height: auto !important;height: 100%;} .middle […]
October 26, 2010

Correct way to access components in your modules

You can also configure modules’ components in the main config file   'modules'=>array( 'my'=>array( 'components'=>array( 'foo'=>array( 'class'=>'FooComponent', 'a'=>'hello', ), ), ), ),  
October 14, 2010

MySQL Regexp to match a number from comma separated list of numbers

I have found regexp select statements useful for databases which have fields of comma-separated numbers. If I need to select all rows with a given number in such a comma-separated list, a regular expression using word boundries would work:   […]
October 12, 2010

Control parent window’s location from a popup

Step 1:  In your parent window document add a function function changeURL(url) { if( url == ""){ url = document.location.href; } document.location.href = url; }   Step 2: In popup document call this function to change URL of parent window opener.document.changeURL('http://www.google.com/'); […]
October 12, 2010

Control parent window’s location from an iframe

Step 1:  In your parent window document add a function function changeURL(url) { if( url == ""){ url = document.location.href; } document.location.href = url; }   Step 2: In iframe document call this function to change URL of parent window parent.document.changeURL('http://www.google.com/'); […]
October 12, 2010

Sign in to multiple account on googletalk

Step 1: Right click googletalk icon and select properties Step2: In the "Target: " text box, enter  "C:YourGoogle TalkPathgoogletalk.exe" /startmenu /nomutex (Please note /nomutex option) Step 3: Click OK.
October 10, 2010

How to customize the error message of a validation rule

The following validation rule uses an error message that is different from the default one class Post extends CActiveRecord { public function rules() { return array( array('title, content', 'required', 'message'=>'Please enter a value for {attribute}.'), // ... other rules ); […]
October 9, 2010

DropDown for pageSize in CGridView

A convenient drop down to select page size and save in User state. Step 1: On top of my controller action for the gridview (if you used CRUD, this is actionAdmin() ) i added: // page size drop down changed if […]
October 8, 2010

Steps required to change project to production mode

Step 1: In config/main.php, add following element to "components" array 'cache'=>array( 'class'=>'system.caching.CApcCache', ),   Step2: In config/main.php, add following element to " components[‘db’] " array 'schemaCachingDuration' => 3600   Step 3: Comment out the following line of index.php defined('YII_DEBUG') or […]
October 6, 2010

Upload and resize image using YII

Download and extract this file in protected/extensions directory.   In config/main.php file, add the following element to components array  'image'=>array( 'class'=>'application.extensions.image.CImageComponent', 'driver'=>'GD', )   Now in action, insert the following code and modify paths $model->Picture = CUploadedFile::getInstance($model,'Picture'); if( is_object($model->Picture) ) […]
October 4, 2010

Automated display of flash messages

Step 1. Put this method into your WebUser class: public function getFlashKeys ( ) { $counters=$this->getState(self::FLASH_COUNTERS); if(empty($counters)) return array(); return array_keys($counters); }  
October 4, 2010

How to change content of a cell in Grid View to a link

If you want to link content of cell in Grid View to some page e.g In orders list, if you want customer’s name to be link that takes admin to customer’s detail page, change the columns of CGrid View as […]
October 4, 2010

Ajax button in CGridView

To add an ajax button to CGridView modify the buttons column  as   'columns' => array( 'id', 'name', array( 'class'=>'CButtonColumn', 'template' => '{view} {update} {delete}', 'buttons'=>array( 'view' => array( 'url'=>'"index.php?r=admin/view&id=".$data->user_id."&m=users"', 'click' => "function (){ $('#viewTab').load($(this).attr('href'));return false; }" ) ), ), […]
October 4, 2010

Display loading div when executing ajax requests

In html add the following div right before closing body tag <div class="ajax-loading"><div></div></div>   Add the following CSS code to stylesheet. (Download loading-bgr.gif and loading.gif) div.ajax-loading{ position: fixed; top: 0; left: 0; height:100%; width:100%; z-index: 9999999; background-image: url('../../images/loading-bgr.gif'); opacity: 0.7; […]
October 1, 2010

Filezilla: Exclude .svn directory from uploading

Open Filezilla Go to View -> Filename Filters  (Ctrl + I) In "local filters" list check "CVS and SVN directories". Click "OK"
September 27, 2010

Exception with Twitter Library "twitter-async" when hosted on Media Temple

Issue: Twitter Library developed by "Jaisen Mathai" throws an exception when uploaded on Media Temple Servers. EpiOAuthException::raise(Object(EpiCurlManager), false) #1 /nfs/c07/h03/mnt/12345/domains/abcde.com/html/protected/components/twitter/EpiOAuth.php(367): EpiOAuthResponse->__get('_resp')  
September 22, 2010

Working with flash messages in Yii

If you would like to inform the user, that his changes were successfully saved, you could add the following line to your Controller: Yii::app()->user->setFlash('success',"Data saved!");   Displaying the flash message in a view is done by if( Yii::app()->user->hasFlash('success') ) { […]
September 21, 2010

Installing Zend 5 on Windows 7

Here’s how I installed it, taken from zend forums (http://www.zend.com/forums/index.php?t=msg&th=7855). This worked for me in Windows 7. Modify the paths below as needed for your installation of Windows 7. Download and install the latest JRE for Windows: http://java.com/en/download/manual.jsp Download and […]
September 18, 2010

Configuration error when starting up NSU

Problem: In windows 7, configuration error appears every time I try to open the Nokia Software Updater. In the help it says to open port 62716 but still that doesn't help.
Configuration error when starting up NSU
This website uses cookies to provide necessary website functionality, improve your experience and analyze our traffic. By using our website, you agree to our Privacy Policy and our cookies usage.