Ahot's weblog

Thursday Oct 16, 2008

Just wondering how python works with arrays. Here is quick sort algorithm written in Python. Only one line of code:

def qsort(L):
    if L == []: return []
    return qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])

[Read More]

Friday Oct 10, 2008

Just found one more solution for getting size of array with CPP. It's based on templates:
#include "stdafx.h"
#include <iostream>

template <class T, int size>
void f(T (&x)[size])
{
 std::cout<<size<<std::endl;
}

int main()
{
 int array[] = {1, 2, 3, 4, 5, 6, 7}; 
 f(array);

 int arrayTwo[] = {1, 2, 3};
 f(arrayTwo);

 return 0;
}

Tuesday Sep 02, 2008

Google Chrome

Today is the day of the one more Internet browser.[Read More]

Wednesday Aug 27, 2008

How to make pagination with MySql? Easy! Just use "select" and "limit" :
SELECT id, name FROM tbl ORDER BY name, id LIMIT 20, 10
This command returns 10 records starting from 20'th. It's very useful feature especially for web programming.
Few years ago I started to work with MSSql. And I was really disappointed: there is no such ability in MSSQL! So huge product doesn't have it!

You can read this entry in my new blog

Here is one solution, that I used:
SELECT TOP 30 id, name FROM tbl ORDER BY name, id
WHERE id NOT IN (SELECT TOP 20 id FROM tbl ORDER BY name, id)
It can looks terrible when you use lots of search and sort conditions.

Update [2008-09-02].
One more MSSQL solution. Using of ROW_NUMBER function in MSSQL 2005+:
WITH tmp_tbl AS
(
    SELECT id, name,
    ROW_NUMBER() OVER (ORDER BY name) AS 'RowNumber'
    FROM tbl 
) 
SELECT * 
FROM tmp_tbl
WHERE RowNumber BETWEEN 20 AND 30;
This case doesn't look simple. However it works faster.
I hope it looks much better now. I spent a lot of time.
Don't tell me that all is terrible :).
Total entries: 39 >>

FEEDS:

BOOKMARKS:

This blog copyright 2009 by ahot