Wednesday, May 9, 2012

Multilevel Dropdown menu for Twitter Bootstarp


Twitter Bootstarp is an excellent responsive UI framework to start your web application. But it seems they are yet to implement a multilevel Dropdown menu. I was googling for it and got couple of solutions and finally came up with my fork :
Update : this was done for twitter bootstrap 2

Pivot Tables

For some reporting started working on some pivot tables. To me these tables are one of those initial rich data visualization formats.
What is it ? :
"In SQL, a pivot table is a set of data that is transformed from a collection of separate rows to a collection of columns. In relational databases, such as Microsoft SQL Server, Oracle and MySQL, pivot tables can be used to simplify extensive data in order to make it easier to read and understand. To create a pivot table, an aggregate is used against a set of data to distribute multiple rows of a single column into a single row with multiple columns. This essentially pivots the result set sideways."
How to :
-Pivot by Aggregated Case Statement
By using an aggregate function (SUM, AVG, MIN, MAX) around a case statement in a SQL query, we are able to achieve the same result as the PIVOT function with less work.
- Sample data: To better understand a pivot table, an example of some sales data is listed here. Copy the following into Microsoft SQL Server Management Studio to try out the examples.
Create table PivotTestTable
(CustName varchar(8),
Item_Type varchar(8),
Item_Amount numeric(6,2))
insert into #PivotTestTable
select 'Jason', 'Computer', 435.34
union
select 'Jason', 'Software', 243.54
union
select 'Jason', 'Monitor', 158.23
union
select 'Alison', 'Computer', 345.89
union
select 'Alison', 'Software', 78.78
union
select 'Alison', 'Monitor', 123.45
- UnPivoted data : When the temp table, #PivotTestTable, is queried, the result is the following.
CustName Item_Type Item_Amount
-------- --------- -----------
Alison Computer 345.89Alison Monitor 123.45
Alison Software 78.78Jason Computer 435.34
Jason Monitor 158.23Jason Software 243.54
As you can see, the result set shows two customers, Alison and Jason, who have purchased three different types of items. There are six rows of data for two customers. If we wanted to see the data in a single row per customer, we would use a pivot table to achieve the desired result.
- Pivoted data : Try the following query and see how the output looks now:
SELECT
CustName as Total_Sales_By_Cust,
sum(case Item_Type when 'Computer' then Item_Amount end) as Computer,
sum(case Item_Type when 'Monitor' then Item_Amount end) as Monitor,
sum(case Item_Type when 'Software' then Item_Amount end) as Software
FROM PivotTestTable
GROUP BY CustName
Or the same can be done as :

SELECT
CustName as Total_Sales_By_Cust,
sum(Item_Type = 'Computer') as Computer,
sum(Item_Type = 'Monitor' ) as Monitor,
sum(Item_Type ='Software' ) as Software
FROM PivotTestTable
GROUP BY CustName

Or you can even COUNT instead of SUM

Currently I am only playing with the SQL to generate the pivot tables; But yeah, there are couple of JS library that you can utilize to play with the Pivot tables on the fly on the client :) :
  1. Pivot.js
  2. jQuery.pivot

Sunday, April 8, 2012

Continuous Integration environment with svn on linux

On my previous post I wrote a way I used to create a CI environment that'd export the entire application to a web location after each commit. I was working then for windows. Now, I have created a setup for Linux - with addition this time the post-commit will only update those files that are actually committed. Following is the post-commit script I got on Stackoverflow:

Reference:

Friday, April 6, 2012

php redirect losing sessions on Chrome/IE issue resolved

My new CodeIgniter app was working beautifully locally - everything's just fine. But when I uploaded to the demo location online - I found I can't login !! After debugging it is discovered - after checking the user credentials and setting the sessions when I was redirecting to the dashboard the user- session was getting lost !
Started with googling for a while and following is the link I got people were suggesting couple of fixes :

Unfortunately, this din solve my issue. I was still getting lost sessions. And finally, [I don remember where I saw someone was suggesting to check the server time] I checked my server time and yes, it was certainly not right - around 5 hours late from the time as it was supposed to be. Fixed the time with the following command [as it was a linux box] :
date +%T -s "10:13:13"
Then, tried login again and bingo - it is working cool.

Reference:
  1. Linux commands to set dates and time

Saturday, March 24, 2012

PHP SOAP client to consume JAX-WS

For couple of days I was googling and researching for a descent solution to my problem to access and consume the services exposed over a JAX-WS from my php application. Actually, I have to write a client so that I can save data from my php application (A subscriber application info management system for the telco company I am working for) to IN database where I have to do so over a JAX-WS interface.
Usually, I woud've followed my previous post. But it din work in this case- the problem and a basic setup is I got from the following location:
http://www.lampjunkie.com/2010/03/get-phps-soapclient-to-speak-with-javas-jax-ws/
But that either din resolve my problem entirely; as my JAX-WS needs a BASIC HTTP AUTHENTICATION to access it. So, following was my solution :

Note:
From php manual I must quote that you must set uri and location directives while invoking webservice with wsdl.I mean when you create the SoapClient object.

Now, that is how I retrieved data from the web service. Next, I will try to save the data and will share how I do it.

Reference:
  1. php manual for soap client. A must read with care of the all the options.
  2. soapUI. A must have tool while working with soap - to easy analyze things.
  3. wsf/php. A framework for php to easily play with enterprise level web services. I will write my experience with it some other time.

Sunday, February 26, 2012

jQuery Datatables plugin and Codeigniter


Just got an work around for the jQuery datatables wrapper [IgnitedDatatables] and made it working on a project to load huge data. As I din get any neat info I had to dig little deep both into datatables plugin and the wrapper and finally made a work around for me. Here in this post I am basically sharing my experience along with keeping records of what and how I did :)
The js I am using on the view to create the datatable and load using ajax is as follow [don try to run on jsFiddle 'cz it has lots of garbage- will clean it up :| ] :


Code on the controller:


And finally the model:


I will write in details on it - how I actually worked on later on this post.
Tips:
  1. For the callback function for the wrapper to work you need to create a helper file where you need to put all the callback functions.
  2. As the wrapper somewhat works as the model should work I have called and made use of it in my model class.
Reference:
  1. jQuery Datatables plugin api
  2. Server side data processing using Datatables plugin
  3. IgnitedDatatables function reference; and Method Chaining example
  4. Example usage code for the IgnitedDatatables library [independent of Codeigniter]
  5. Sample MySql Database [Sakila :)]

Sunday, February 12, 2012

Dynamically add a group of fields using jQuery

Its not a so tough thing, tough. Just wanted to keep a record and add a tip :) Following is the code I am using:

Note:
I was facing a problem, when the groups of fields grows  more then the view area for each click to create the window jumps to the top of the page; To resolve, to remain where I was creating the new fields I just added one line return false as the last line of the click even.
Instead of remaining the same place if you want to scroll to some where else you can use the following jQuery plugin:
scrollTo

Wednesday, February 8, 2012

Manipulating Auto Increment values in MySql



  1. Set the MySql variables auto_increment_increment and auto_increment_offset variables.
  2. Play with the Auto_Increment in Information schema.
To start with an AUTO_INCREMENT value other than 1, you can set that value with CREATE TABLE or ALTER TABLE, like this:
ALTER TABLE tbl AUTO_INCREMENT = 100;
Note:It is not possible to confine the effects of these two variables to a single table, and thus they do not take the place of the sequences offered by some other database management systems; these variables control the behavior of all AUTO_INCREMENT columns in all tables on the MySQL server. If the global value of either variable is set, its effects persist until the global value is changed or overridden by setting the session value, or until mysqld is restarted. If the local value is set, the new value affects AUTO_INCREMENT columns for all tables into which new rows are inserted by the current user for the duration of the session, unless the values are changed during that session.


Wednesday, December 21, 2011

Unload/Uninstall Trend Micro Office Scan client 10.5


Trend Micro.svg


I wonder why to block the everything instead of trying to grow the culture for trust and reliability and ownership ? I wonder why this freaking Trend Micro's Office Scan to narrow down the accesses ?! I was ok with it untill when they locked access to my external devices which is really essential for me to back all my things up. After couple of google here is the solution I got to Unload(disable) or Uninstall Trend Micro Client where a prompt comes up for a password.

  • Go to the ..\Trend Micro\OfficeScan Client directory. Usually, it would be: 

C:\Program files\Trend Micro\Officescan Client\

  • Locate and open the Ofcscan.ini[this is the file where all the configuration setting for the OfficeScan client is stored ] file using any text editor. You may use notepad to edit. 
  • Find [INI_CLIENT_SECTION] section. 
  • Change the value of the Uninstall_Pwd to 

!CRYPT!523F7DC2E525044E2800FCDEA7E5D78B70C0A4165387060525E3EE66D5D2D2F460EA361E712B5F871FD473C7A6C
  • Change the value of the Unload_Pwd to 
!CRYPT!523F7DC2E525044E2800FCDEA7E5D78B70C0A4165387060525E3EE66D5D2D2F460EA361E712B5F871FD473C7A6C
  • Save and close the file.
  • Right click on the Officescan client on your system tray then click on Unload Officescan
  • Once it prompts you for the password type trendmicro as the password.
You should be able to see your officescan client on the system disappear. Now you are free from all the blocking imposed by this tool. I can access my external devices... o la la :D


Note: 
  • If you can't save the Ofscan.ini file [windows 7] open the editor as administrator - right mouse on the editor program and click run as administrator.
  • If Client_Allow_Uninstall / Client_Allow_Unload set to 0 make it 1.
  • If UnloadProtect is set to make it 0.



Wednesday, December 7, 2011

My Instant Continuous Integration environment for development


A simplest dev environment for continuous integration for a dev team [considering a php project with mysql db] :
1. Install Visual SVN server - its for windows and easy to install and manage SVN server.
2. Create a post commit hook for the repo; to do that - In the VisualSVN Server GUI Tool:
-Select your repository
-Right click Properties Select the Hooks tab
-Select the Post-commit hook
-Click the Edit button.
-Enter a line like this into the textbox:
c:\program files\visualsvn server\bin\svn.exe" export https://svn.yourserver.com:4433/svn/YourRepository/Websites/YourWebsite/ C:\inetpub\wwwroot\YourWebsite --quiet --non-interactive --force --username youruser --password yourpassword
-Click Ok.
3. Now for the DB Sync follow the steps in the following article : [However, you might need some modification to meet your need]
http://www.decodephp.com/2008/09/29/svn-and-mysql-schema-synchronization/

Surely, You can add more flavor to this environment, like you can add a script to run each day so that it grabs all the commit logs and emails to the test team and/or stack holders or may to the entire team - so that everybody remains better informed.

Hope this will help us a to remain synced in an Agile team.
Those who is not aware of the term Continuous Integration, you can check this wikipedia link