Welcome to Kodok Marton's homepage

Professional work from professionals!

  • Increase font size
  • Default font size
  • Decrease font size
Home Programming
Programming


Resources for faster programming - time-honored methods

A gyorsabb programozast elosegito eroforrasok

 

How to count all NULL values in a table?

The other day I came across with a situation when a guy asked about how can he count all NULL values in a table, not only on a specific column.

He wanted to use the value for their contacts database report. Where all the columns for a contact is preferred but not mandatory, he just want to generate a quick report on the completion percentage of contact information in the entire table. He wanted to count from all the columns and not from one.

Read more...
 

Getting a list of days from SQL date range (the most surreal query ever seen)

I asked a few days ago on a forum for help, to run a TSQL query like

select ... as days where `date` is between '2010-01-20' and '2010-01-24'

And return data like:

days 
---------- 
2010-01-20 
2010-01-21
2010-01-22
2010-01-23
2010-01-24 
I ended up with the most surreal query ever seen in my life:
Read more...
 

How to properly get user's birthday from database (solution for 29th February)

Today, I came across a problem, where I had to get from database all users that celebrate today. This is not as easy as it sounds, as there are leap years, and users having their birthday on 29th February will be returned only in 4 years. It's better return them on 1st March if the 29th February doesn't exists in that year. Actually, if you need to be serious about this, you have to take into account, that every 100 years, there's no leap year, but every 400 there is. 

Here is an answer that property takes into account leap-years and will always give you the users whose birthday is on the 29th of February at the same time as those on the 1st of March.

SELECT * 
  FROM USERS
  WHERE
     DATE_FORMAT
(FROM_UNIXTIME(birthDate),'%m-%d') = DATE_FORMAT(NOW(),'%m-%d')
     OR
(
           
(
                DATE_FORMAT
(NOW(),'%Y') % 4 <> 0
                OR
(
                        DATE_FORMAT
(NOW(),'%Y') % 100 = 0
                        AND DATE_FORMAT
(NOW(),'%Y') % 400 <> 0
                   
)
           
)
            AND DATE_FORMAT
(NOW(),'%m-%d') = '03-01'
            AND DATE_FORMAT
(FROM_UNIXTIME(birthDate),'%m-%d') = '02-29'
       
)

 

 

What makes each major language “special”?

It's been said that any language that doesn't change your way of thinking about programming isn't worth learning. It would be interesting to compile a list of what makes every major language "special". These would be the features that are unique to the language (at least compared to languages of similar or greater popularity and/or in terms of the level of emphasis placed on them), that one has to understand to "think in" the language, and that make the language worth learning even if you can't make any money by learning it. Here are some examples:

  • C: Pointers, manual memory management, low-level unchecked programming.
  • C++: RAII, templates.
  • D: Templates on steroids, compile time function evaluation, insanely powerful compile time introspection/reflection, the ability to program at a very high level and a very low level in the same language.
Read more...