Saturday, November 14, 2015

PHP : Wordpress : Comments template not rendering

Somehow my new custom post type was not able to get the comments section. After debugging and looking for option found solution for this issue at WP Questions.

I just updated the wp_posts with below mentioned query:

UPDATE wp_posts SET comment_status = 'open' WHERE post_type = 'myposttype';
 And  it worked.

Tuesday, January 14, 2014

PHP : Wordpress : Increase media file size

Working on WordPress was a great change for me. But for media upload I wanted to increase the upload size for file selected. Checked several plugins but was not working properly. One of the comment by Shane G on WordPress support site I found useful.

Just add below code in .htaccess file.
php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200
And it works like a charm.

Wednesday, November 20, 2013

Eclipse : Birt : Build JDBC:MYSQL connection

For connecting the reports to mysql database was fun.
For that I followed the birt-installation-and-configuration which was easy to understand.

Now as per the tutorial for adding external file
Select Project > right click > properties > Classpath > Add external JARs and go to path /usr/share/java folder(For Ubuntu and for windows please check the link above).



Once this is done we create the new data source with mysql connection.
Navigator(in sidebar) > Data Source > Right Click > New Data Source

 

Once data source name is given click Next and
Select com.mysql.jdbc.Driver(v5.1)
Database URL add : jdbc:mysql://your_host_name/your_db_name
User Name and Password of the connection
Click on Test Connection
It should display dialog box as shown in the image below indicating that the connection is successfully build.

Monday, October 7, 2013

Liferay : Portlets : Task cannot continue because ECJ is not installed

While going through Liferay Portal 6.0 - Development Guide : Creating a Portlet I got error on running ant task.
Task cannot continue because ECJ is not installed.
ECJ was automatically installed. Please rerun your task.


After searching for solution got Solve ECJ error in liferay IDE on Liferay Solutions.

Just followed the steps suggested.
Window -> Preferences -> Ant -> Runtime 
Then Ant Home Button and  Add external jar called ecj.jar which was in plugin-sdk-folder-path/lib



And After running the Ant Task portlet deployed successfully.

Monday, September 9, 2013

SQL : Stored Procedures : Next working date

Working on stored procedures is fun. For 1 functionality, wanted to get next working date which will exclude saturday sundays and dates from holiday list table.

I got really nice solution on mysql-stored-procedure-for-computing. But only draw back was Recursive limit. But tried the solution added in comments.

Checked and it worked fine. Only change done in this solution that if no date provided for function it should take current date. And parameter numDays removed.

So if current date is 2013-09-04. 2013-09-05 and 2013-09-06 in holiday list table. 2013-09-07 is Saturday and 2013-09-08 Sunday.








The output should be















And instead of both functions changed one to stored procedure as below.
Stored Procedure : sp_get_next_working_date
/**
Stored Procedure : sp_get_next_working_date
Parameter : p_date as date
Description : Returns next working date excluding Saturday/ Sunday OR Date in holiday list table.
Dependency : Function fn_check_date_if_in_holiday_list 
**/

BEGIN
  DECLARE next_working_date DATE;
  SET next_working_date = p_date;

  IF p_date = 0 THEN 
    SET next_working_date = DATE(NOW()); 
  END IF;
  SET next_working_date = DATE_ADD(next_working_date, INTERVAL 1 DAY);

  WHILE fn_check_date_if_in_holiday_list(next_working_date) DO 
    SET next_working_date = DATE_ADD(next_working_date, INTERVAL 1 DAY);
  END WHILE;

  SELECT next_working_date;
END
Function : fn_check_date_if_in_holiday_list
/**
Function : fn_check_date_if_in_holiday_list
Parameter : p_date as date
Description : Checks if date is Saturday/ Sunday OR in holiday list table.
Dependent : sp_get_next_working_date
**/

DETERMINISTIC
BEGIN
  DECLARE dayOfWeek INT DEFAULT 0;
  DECLARE result BIT DEFAULT false;
  DECLARE holidayCount INT DEFAULT 0;

  SET dayOfWeek = DAYOFWEEK(p_date);
  SELECT COUNT(*) from TBLholidays where holiday_date = p_date INTO holidayCount;

  IF dayOfWeek = 7 or dayOfWeek = 1 or holidayCount > 0 THEN 
    SET result = true;
  END IF;

  RETURN result;
END

Thursday, September 5, 2013

Rails : Tasks : Truncate db with 1 command

Back to rails is fun.

Working on some project I wanted to clean the database to clear all junk data added while testing.

But wanted to do that with 1 command and checking if I can get clear database without opening pgadmin or run several commands like drop/ create/ migrate. And I also added seeds in the project to get default data for functionality.

I checked rake --tasks. Check below screen-shot with selected text.












That was the command which I was looking for. It worked. But it thrown error first that it can not drop database as per the notes in --tasks. But it first truncated/ migrated and at last the seeds were added to the tables. Easy....:). Loved it....:D

Wednesday, August 28, 2013

SQL : CASE statements

Using conditions in SQL statements is really useful. Specially when we need to compare 1 value based on conditions with multiple columns.

For example I have 1 table called tasks. Where I need to check the given date parameter should be greater than or equal to multiple columns based on the current tasks category.

I can easily do that by code. Can be ROR or PHP. But if we can get the data directly from database it gets really fast for any language.

In this situation CASE statements are really useful.

In this example I need to compare parameter date to start_date column if category is 'appointment' and to end_date if category is 'todo'.
SELECT * FROM tasks 
WHERE '2013-09-02' >=
CASE 
  WHEN tasks.category='appointment' THEN (date(start_date))
  WHEN tasks.category='todo' THEN (date(end_date))
END

Monday, August 26, 2013

Rails/ PHP : Ubuntu : Add autostart on system boot

There is never a thought of starting an application if working in PHP.
But for one of the project we were using node.js and if the PC gets restarted we have to manually start the node.js.

I have done this before for my local rails application previously(http://stefanwienert.net) and applied the same for this issue.

First added .conf file
sudo gedit /etc/init/run_nodejs.conf
This will open default editor with new file called run_nodejs.conf
Now add following text to the file
description "Run Node JS"

start on (net-device-up and local-filesystems)
stop on runlevel [016]
chdir /path_to_nodejs

setuid user_name  # set to the user, which should run the app
exec sudo -u user_name  "/path_to_nodejs/nodejs.sh"

respawn
## give up if I respawn 3 times in 60 seconds...
respawn limit 3 60
Now create 1 .sh file named nodejs.sh at location /path_to_nodejs.

and in nodejs.sh add following commands, to start node js services.

Also give permissions to the file as chmod +x nodejs.sh to make is executable.
and then just check with (.conf file name for following command)
sudo start run_nodejs
You can also restart and stop the service.

As I mentioned I have done this for rails application.
But had 1 issue. By default I have 1.9.3 ruby version for other projects and for only local project I am using 2.0.0.

In demoapp.sh I have added following code
#!/bin/bash
PATH=$PATH:/home/supriya/.rvm/bin
source "/home/supriya/.rvm/scripts/rvm"
source ".rvmrc" 

rvm use 2.0.0
rails s # -p port_u_want -e env_u_want
So with these commands after starting my pc I get my local demoapp project always running with 2.0.0 and no worries about the default gemset.
And while working on project I can run log with if any error checking
sudo tail -f /var/log/upstart/demoapp.log

Tuesday, July 23, 2013

Collection : Thenewboston (Video Tutorials)

Most of people find video tutorials very helpful more than reading books. As we understand more with watching practical examples.

Looking forward to other technologies I found a very useful site TheNewBoston by Bucky Roberts, who provides video tutorials for multiple languages like java, android, php, ruby and more.
Just go to tutorials section and check the list, for technologies you want to learn.

Sunday, June 16, 2013

PHP : Excel Reader

Reading excel sheets now a days is not that big challenge, but reading it with very advanced formulas is definitely a very big challenge. One of team really spent a very pressured day to work on this functionality.

We used PHPExcel but was not reading values from other sub-sheet while performing getCalculatedValue(). Everything else was working fine. Like dynamically adding new values and generating the excel. After opening the new excel it worked like the original with new values. But the main functionality which we wanted, was getCalculatedValue() to display the calculations on web page.

After checking other plugins we found one more excel reader at devzone.zend.com. Tried with our excel sheet which worked like a charm.

Really useful for getting advanced formulas calculated values. There is also a excel writer but I didn't check it yet.
The only limitation to this plugin is that it do not work with xlsx file.