Memcached Server with Rails

To install memcached server on linux/fedora box
yum install memcached

Find help for memcached commands and option
memcached -help

Start memcached server(11211 is default port Number for memcached server)
memcached -m 500 -l 192.168.2.4 -p 11211 -vv
(192.168.2.4 this is my local ip address you can cahnge that)

Stop the Memcached server
ps -ef|grep memcached
kill PROCESS_ID

start memcached server with
memcached -m 500 -l 192.168.2.4 -p 11211 -vv

How to install on Windows server:
1.  Downloaded this Win32 port of memcached by Kenneth Dalgleish.(download from following url)
http://thewebfellas.com/blog/2008/6/9/rails-2-1-now-with-better-integrated-caching
2. Extracted the files to C:\Program Files\memcached
3. Opened a command prompt in the folder and installed memcached as a service using memcached -d install
4. Started the service using net start “memcached Server”

How to use memcache in Rails app?
Open  /config/environments/development.rb for development mode,
production.rb for production mode.
paste following line into file.
config.cache_store = :mem_cache_store, ‘127.0.0.1’, ‘127.0.0.1:11211’ , { :namespace => ‘dev’ }
(127.0.0.1 this is my local ip address you can cahnge or point out to any server where memcached server is running)
Restart mongrel server. you are ready to use memcached server

How to use in Rails
@user= User.find(1)—–OLD Code

New Code With Caching:
@user = cache([‘User’,1],:expires_in => 30.minutes) do
User.find(1)
end

Easy Steps for setting up nginx with php on Linux

I am using Fedora 10 so for that linux version i used these commands for setting up my server.

Installing Nginx:
yum install nginx

Then we create the system startup links for nginx:
/sbin/chkconfig –level 35 nginx on

We can make PHP5 work in nginx through FastCGI.For that install all this packages:
yum install lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mhash php-mssql php-shout php-snmp php-soap php-tidy

Then open /etc/php.ini and add the line cgi.fix_pathinfo = 1 right at the end of the file:
vi /etc/php.ini
paste this line :- cgi.fix_pathinfo = 1

To start a PHP FastCGI daemon listening on port 9000 on localhost and running as the user and group nginx, we run the following command:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

To restart PHP FastCGI daemon, Use this command:
ps -ef|grep php-cgi
kill PROCESS_ID

you don’t want to type in that command manually whenever you boot the system, so to have the system execute the command automatically at boot time, open /etc/rc.local…
vi /etc/rc.local
and add the command at the end of the file:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx  -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

THEN STOP THE APACHE WEB SERVER:
/sbin/init.d/httpd stop
To stop apache on every startup:
/sbin/chkconfig –level 35 httpd off

First take backup of your nginx configuration file:
cp /etc/nginx/nginx.conf nginx.conf_cp
use nginx.conf file from life180 “config/nginx” folder

deconstructing date_select in rails

// Reconstruct a date object from date_select helper form params

// place this code into your application.rb file
def build_date_from_params(field_name, params)
Date.new(params["#{field_name.to_s}(1i)"].to_i,
params["#{field_name.to_s}(2i)"].to_i,
params["#{field_name.to_s}(3i)"].to_i)
end

//You can changes order of displaying into view
<%= date_select ‘from’, ‘date’ ,:order => [:day, :month, :year] %>
<%= date_select ‘to’, ‘date’,:order => [:day, :month, :year]  %>

//goes into controller -- add your own error handling/defaults, please!
@from = build_date_from_params(:date, params[:from])
@to = build_date_from_params(:date, params[:to])

Comparing date time into controller

@users_reports = User.find(:all, :conditions=>[‘created_at >= ? and created_at < ?’, @to, @from])

How to add HTML code on WordPress home page

Some time we want to show Some custom text or HTML code on home page. In this article we given tricks and steps to add HTML code on WordPress home page.

How to add HTML code on WordPress home page

  • First method

you need go to wordpress admin panel.Create page with home name. Add your HTML or custom text in that page.

Go to Setting->reading section. There is “Front page displays”  section. We can found following two radio box over there.

  • Your latest posts
  • A static page (select below)

Select “A static page (select below) ” radio box. Than from “Front page:” select box, select the Home page. That sit.

How to add HTML code on WordPress home page
How to add HTML code on WordPress home page
  • Second Method

If you want to add some different text or HTML code, than you need open functions.php file which you found in wordpress themes folders. Just copy and paste following code in that file.


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php

if (is_home() {
echo "HTML CODE GOES HERE OR TEXT";

}

?>

Note: You need replace HTML code. I used sample text in code.

Have fun!

How to fetch Feedburner Subscriber Count in wordpress

We all are using the feedburner button in wordpress sites. In this article showing, How to fetch Feedburner Subscriber Count in wordpress website using our code.

How to fetch Feedburner Subscriber Count in wordpress

Just copy paste the following code in your sidebar.php file(This file you will find in your template folder.)

<?php

//You need to change the uri parameter to your website name
$whaturl=”http://api.feedburner.com/awareness/1.0/GetFeedData?uri=wordpressapi/ZoqV”;

//Initialize the Curl for using the feedburner api
$wordpressapi = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($wordpressapi, CURLOPT_RETURNTRANSFER, 1);

//Set the URL
curl_setopt($wordpressapi, CURLOPT_URL, $whaturl);

//fetching data
$data = curl_exec($wordpressapi);

//Closing connection
curl_close($wordpressapi);
$xml = new SimpleXMLElement($data);
$fbcount = $xml->feed->entry[‘circulation’];
echo $fbcount;
//end get cool feedburner count
?>

Echo $fbcount will print the feed Subscriber count.

add custom header to different categories in WordPress

wordpress tutorial for add custom header, footer, or sidebar for different categories in WordPress. we have given simple conditinal code which need to use in your theme file.

add custom header to different categories in WordPress

If you want to add the different header for each category then use the following code in your index.php where “get_header()” method is called.

Create the Header-new_category.php file and put your header code in that file as per requirement.

For sidebar use this code:


<?php if (is_category(‘new_category’)) {
get_header(' new_category ');
} else {
get_header();
} ?>

Create the Header-new_category.php file and put your header code in that file as per requirement.

For sidebar use this code:


<?php if (is_category('New_category')) {
get_sidebar('new_category');
} else {
get_sidebar();
} ?>

Create the sidebar-new_category.php file and put your sidebar code in that file as per requirement.

For Footer use this code:


<?php if (is_category('New_category')) {
get_footer('new_category');
} else {
get_footer();
} ?>

 

 

Create the footer-new_category.php file and put your footer code in that file as per requirement.

Cheat Sheets for creating WordPress Themes and Plugins

Here is the list of cheat sheets which are very useful when your developing new theme or plugin. For wordpress theme developer and plugin developers cheat sheets are very important. We collected the nice collection Cheat Sheets for creating WordPress Themes and Plugins.

Cheat Sheets for creating WordPress Themes and Plugins

WordPress Theme Development Checklist

Download PDF : Download Cheat Sheet »
Source : http://startbloggingonline.com

WordPress Theme Development Checklist

WordPress CheatSheet

Download PDF : Download Cheat Sheet
Source : andywibbels.com

WordPress CheatSheet

The WordPress Help Sheet

Download PDF : Download Cheat Sheet
Source : http://www.fylrr.com

The WordPress Help Sheet

WordPress SEO Cheat Sheet

Download PDF : Download Cheat Sheet
Source : tekka.de

Wordpress SEO Cheat Sheet

WordPress Template Tags

Download PDF : Download Cheat Sheet
View HTML Version : View HTML Cheat Sheet
Source : bueltge.de

WordPress Template Tags

WP Widget Cheat Sheet

Download PDF : Download Cheat Sheet
Source : bueltge.de

WP Widget Cheat Sheet

WordPress Loop

Download PDF : Download Cheat Sheet
Source : bueltge.de

WordPress Loop

WP Plugin API Cheat Sheet

Download PDF : Download Cheat Sheet
Source : bueltge.de

WP Plugin API Cheat Sheet

learn html basics with notepad

We will learn html basics with notepad. html is a basic web design language here i going to show you how to make simple web page using notepad only. In windows.

learn html basics with notepad

notepad

learn html basics with notepad
learn html basics with notepad

first step
open notepad

goto start >> all programs >> accessories >> notepad

now your notepad is open
in web pages having so many types of code so we have to mention bout which code is write
for, this thing will be eiser to write comment on every new code
comment start with // , when web page is run on browser it’s can’t consider that comment

// html language start with this tag in html language every tag tag have to open
& close so here i am given close tag also

<html> // here is open tag
</html> // here is close

now html have internal two parts one is “head” tag & second one is “body” tag in head tag
have to declare web page title also in upcoming article i will show how we can use body tag
for links
body tag is main part of our html web pages here we can write what i have to show in browser
so first head tag

<html>
 <head>
 <title>first webpage</title> // here is title which can seen in title of browser
 </head>
</html>

now start our body tag

<html>
 <head>
 <title>first webpage</title> // here is title which can seen in title of browser
 </head>

 <body>
 this is my first web page in html language !!
 </body>
</html>

now save this notepad file goto file >> save

name it first “webpage.html” & open it in your favourite web browser

wordpress database migration steps

WordPress domain migration is every time required. We given simple wordpress database migration steps. Using following steps you can do domain migration. Whenever you need to push wordpress site local box to production or qa box. you need to change the domain name. I given the simple steps for wordpress database migration. Using following steps you can do the wordpress domain migration.

wordpress database migration steps

First go to wp-config.php file and change database name(what you want)
1. wp_1_options -Table name
option_name column – change(siteurl and home)

2. wp_blogs- Table name
domain column – change

3. wp_site- Table name
domain column – change

4. wp_usermeta
meta_key column – change(source_domain)

use this for
changing all post path and image path
UPDATE wp_1_posts SET post_content = REPLACE(post_content, ‘siwan.wordpress.com’, ‘localhost.localdomain’);

Following Articles are helpful to do the wordpress domain migration.

https://purabtech.in/mysql-queries-wordpress-website-migration/

https://purabtech.in/wordpress-migration-hosting-service-domain/

find replace content in post wordpress

Some times we need to change specific text in wordpress. Using mysql database query or PHPmyadmin interface, you can find replace content in post wordpress. We have given mysql query for replacing the content using database.

find replace content in post wordpress

Use this query for wordpress users


UPDATE wp_1_posts SET post_content = REPLACE(post_content, 'www.test.com', 'www.secondtest.com');

Use this query for wordpress

UPDATE wp_posts SET post_content = REPLACE(post_content, 'www.test.com', 'www.secondtest.com');