jQuery.gTabs plugin - tabbed interface plugin

February 7th, 2008 by Denis Golovtsov

Hi, everybody!

Let’s dance for a little around my favorite JavaScript framework jQuery!

Today I’d like present you my new creature based on it.
This is new jQuery plugin the purpose of which gives you easy way to create tabbed UI elements on your pages.

Let’s look the peaces of code.

JavaScript initialization code:

$(‘#gTabs_1′).gTabs([‘tab 1′,‘tab 2′, ‘tab 3′,‘tab 4′]);

HTML part of code:

<div id=“gTabs”></div>

<div id=“_tabs_0″ class=“_tabs_area”>body of tab 1</div>
<div id=“_tabs_1″ class=“_tabs_area”>body of tab 2</div>
<div id=“_tabs_2″ class=“_tabs_area”>body of tab 3</div>
<div id=“_tabs_3″ class=“_tabs_area”>body of tab 4</div>

The picture shows how it will look on a page:
shoot1

Main features of jQuery.gTab plugin which I consider as its specific advantages:

  • Myself exclusive design of tab labels (items), which I consider as very compact, smart and quite pretty. I have got in from the one of mine old successful project. When I had seen it again, I decided to relive good solution.
  • It’s support multi instance of tabbed controls on the page.
  • You can bind yourself handler, which will get content for new tab by Ajax for example.

Download, get more details and see other interesting examples of usage you can on the jQuery.gTabs page.

I will happy to see your comments about, thank you in advance!

Gengo patch for WordPress 2.3.x

January 8th, 2008 by Denis Golovtsov

For whom it’s interesting, you can download patched by me Gengo for WordPress 2.3.x here.

The patch is still be not stable, because code of Gengo is quite complex, therefore it’s not trivial task to fix it, if you are not owner of code. Any way plese post me about any problems there and I will try to fix as far as I will have time for it.

Also I’d like to notice that patch was made without try to keep backward capability with earlier version of WordPress. It was “dirty” hack, purpose of which was only to make it working with my WordPress (v2.3.2). Any way you can post me about any problems.

And finally of course thanks a lot to author of this very well plugin.

PotgreSQL OLEDB provider for ASP.NET

December 13th, 2007 by Denis Golovtsov

I read the information on the official PostgreSQL site that the first commercial OLEDB provider for PotgreSQL is available now. I estimate this news as very good.

I have been working with PostgreSQL very closely for one year and I found that this server is very powerful and as now .NET framework will have OLEDB provider for a supporting of that, it can be a good alternative of the MS SQL and Oracle servers, licenses of which cost much money.

I have downloaded th trial version of it from the author’s site and have checked how it works. Of course trial version has serious limitation here:

TRIAL VERSION

The trial version has the following limitations:

- SELECT statements return up to 100 rows.
- DB conversion in DTS/SSIS Wizard handles only first 100 rows in every table.

Also I proud that the its developer is Russian programmer, who works and lives in USA now. Thank him very much for his good job. And if I will have .NET project where by some reasons will choose PostgreSQL server I obviously can play with its not trial version also, which doubtless will be interesting.

The estimate of your PHP skills and some pictures from the Netherlands

December 4th, 2007 by Denis Golovtsov

Nice test which allow to estimate your PHP skills

Nice test, recommend to play in this everybody who knows Russian and PHP little ;)

The Netherlands photos

Other good news came from the Netherlands as the collection of photos with my. Thank you very much for this to Nikos, which finally found his photo camera and sent those photos to me ;)

Update: also available photos shoot by myself during this very nice journey. As you can see some of Nikos photos illustrate the moment when I was shooting something myself, that is fun to see yourself from the side ;)

CodeIgniter memory leak in “Generating Query Results” functions and solution for this

November 22nd, 2007 by Denis Golovtsov

I found that CI framework has memory leak in collection of functions which are described in “Generating Query Results” of CI manual. Those functions need to get access to rows in database result object.

The source code of those function can be found in file: $CI_DIR\system\database\DB_result.php.

Investigate shows that every functions there based on 2 main functions: result_object(), result_array().
The difference between them is type of container which they uses to store values, the first function uses object, second uses associative array. So look at the one will enough to understand the problem and where is source of headache there.

function result_array()
        {
                if (count($this->result_array) > 0)
                {
                        return $this->result_array;
                }

                // In the event that query caching is on the result_id variable
                // will return FALSE since there isn’t a valid SQL resource so
                // we’ll simply return an empty array.
                if ($this->result_id === FALSE OR $this->num_rows() == 0)
                {
                        return array();
                }

                $this->_data_seek(0);         
                while ($row = $this->_fetch_assoc())
                {
                        $this->result_array[] = $row;
                }
               
                return $this->result_array;
        }

Have you guessed it already?
The problem in cycle. In where we walk trough all items, keep every in container array and then return this array. Obviously, if database result has enough many records, as I had in my case, it will work till we will have free memory, then we will get fatal error something like this:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 33 bytes) in /var/www/html/tagnet/system/database/DB_driver.php on line 173

It means that our memory finished. My query had returned approximate 300,000 records, so I suppose it’s not extraordinary case.
Why has authors used such solutions there? I think they would like to use foreach construction very much for a walking in result.

I did not find in google how people solve this problem, may be I was not lucky in my searches. But I found description of the similar problem here. But this problem was fixed by authors of CI.

Bay the way, how I solve this problem?

foreach($result->result_array() as $row) {

}
while ($row = $result->_fetch_assoc()) {

}

Of course it’s not good that I have used “private” member of class CI_DB_result, but I still use CI API for fetching rows and don’t use database dependence functions.

Russia - England 2:1

October 17th, 2007 by Denis Golovtsov

Ole, Ole, Ole - Russia, Go-Go-Go!

We are the Champions!

It was wonderful.

I have fell as we would had won Brazilian in final of World Champions …

It is big gift our players to whole Russian people, thank all of them for this !!!

How add sort direction icons next to the header text in DataGrid (ASP.NET 1.1)

October 11th, 2007 by Denis Golovtsov

This question belongs to FAQ for a long time, but for me as newest in ASP.NET it was not obviously.
So I’d like to present the solution which is mine transformation from ASP.NET 2.0 to ASP.NET 1.1 of found in the Internet.
Original solution can be found there.

public class MyPage: System.Web.UI.Page
{

        protected DataGrid myDataGrid;

        private void Page_Load(object sender, System.EventArgs e)
        {
                if (!Page.IsPostBack)
                {
                        DataBinder();
                }
        }

        // method bind source data to DataGrid control
        private void DataBinder()
        {                     
                DataView objDataView = new DataView(/* …get DateTable object here … */);
                objDataView.Sort = SortExpression;
                myDataGrid.DataSource = objDataView;
                myDataGrid.DataBind();
        }

        // property stores latest sort direction of DataGrid between states
        public string SortDirection
        {
                get
                {
                        return Session[“myDataGridSortDirection”] == null
                                ? “ASC”
                                : Session[“myDataGridSortDirection”].ToString();
                }
                set
                {
                        Session[“myDataGridSortDirection”] = value;
                }
        }

        // property stores latest sort experession of DateGrid between states
        public string SortExpression
        {
                get
                {
                        return Session[“myDataGridSortExpression”] == null
                                ? “ID”
                                : Session[“myDataGridSortExpression”].ToString();
                }
                set
                {
                        Session[“myDataGridSortExpression”] = value;
                }
        }

        // binding event handlers
        private void InitializeComponent()
        {
                this.myDataGrid.ItemCreated
                        += new DataGridItemEventHandler(this.myDataGrid_ItemCreated);
                this.myDataGrid.SortCommand += new DataGridSortCommandEventHandler(this.myDataGrid_SortCommand);
                this.Load += new System.EventHandler(this.Page_Load);

        }

        // below handler is invoked for render every output item of DataGrid
        // this is place and moment when we will add icon image which will show current sort direction
        private void myDataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
        {
                if (e.Item.ItemType != ListItemType.Header) return;
                if (!e.Item.HasControls()) return;

                foreach (Control control in e.Item.Controls)
                {
                        if (!control.HasControls()) continue;
                        LinkButton button = (LinkButton)control.Controls[0];

                        if (button != null && SortExpression.IndexOf(button.CommandArgument) != -1)
                        {
                                HtmlImage image = new HtmlImage();
                                image.Src = “images/sort_”
                                        + ( SortExpression.IndexOf(“ASC”) != -1
                                                ? “asc”
                                                : “desc” )
                                        + “.gif”;
                                control.Controls.Add(image);
                                break;
                        }
                }
        }

        // sort event handler
        private void myDataGrid_SortCommand(object source, DataGridSortCommandEventArgs e)
        {
                SortExpression = e.SortExpression.ToString() + ” “ + SortDirection;
                SortDirection = SortDirection == “ASC” ? “DESC” : “ASC”;
                DataBinder();
        }

}

Comment about SortDirection and SortExpression properties:
I prefer use Session object here, because it gives possibility to restore value, when user left section and then goes back, instead of ViewState, which usually is used for this in almost of solution which I saw in the Internet.

GolDen blog relive!

October 11th, 2007 by Denis Golovtsov

During 22 September when our administrator start to prepare our servers for a journey to new office, my site hasn’t worked and I haven’t marked it because from local network it still works fine ;) Before one of my colleagues (Alexander Stankevitch it’s you) told me that he cannot access to my site, I didn’t believe him and told that may be he try use not enough good browser for my site ;), but 1 day ago suddenly I understand that problem really takes place, because IP of hosting server was changed and I need update DNS settings for that. So I did update of DNS and site relive again! Thank you Alexander very much!

Small ASP cheat sheet: getting current path (absolute URL), getting current script name.

September 21st, 2007 by Denis Golovtsov

Again I’d like to present small collection of solutions for my not favorite technology (not confuse it with ASP.NET which I respect).

When need get the default URL for the current sub folder (that can be used for example to present a link on this section of site in mail), can be used following code:

‘ getting absolute path for current sub folder

path = Left(Request.ServerVariables(URL),InstrRev(Request.ServerVariables(URL),“/”)

‘ if url need for a putting in email for example, so protocol and server name must e added

url = “http://” & Request.ServerVariables(“SERVER_NAME”) & path

Also can be helpful getting the name of current script (for a generating conditional dependent content for example), following peace of code will helpful:

file = Right(Request.ServerVariables(URL),Len(Request.ServerVariables(URL)) - Len(path))

In this case we use the path variable that need get before, and if we’d like to get file without calculate it, we should use following code:

file = Mid(Request.ServerVariables(URL),InstrRev(Request.ServerVariables(URL),“/”)+1)

ASP VBScript function to generate random password

August 17th, 2007 by Denis Golovtsov

Sometime I have to work with ASP projects. I don’t like ASP. At first because it’s old technology which almost doesn’t use in new projects now and this experience won’t very helpful. Any way I’d like to present here one simple function that might help someone.


‘       Generate random password

‘       @author Denis Golovtsov, http://goldenman.spb.ru/
       @param length integer - Tne length of generated password.
‘       @output string - Generated password.

Public Function NewPassword(length)

Dim range,password

range = “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”
password = “”

Randomize

While length > 0
password = password & Mid(range, 1 + Int(Len(range) * Rnd), 1)
length = length - 1
Wend

NewPassword = password

End Function

I’m sure all are clear there and it doesn’t require additional comments.