Nice Programmer`s Font

Filed Under (General) by Wenbert on 27-02-2008

Tagged Under :

http://www.dafont.com/font.php?file=bitstream_vera_mono

Very readable!

Get number of hours between 2 timezones

Filed Under (General) by Wenbert on 21-02-2008

Tagged Under : ,

Here is a way to get the number of hours between two different timezones. I am sure that there is a way of doing it shorter and faster, but I did it this way for readability purposes.

  1.  
  2. date_default_timezone_set("America/Kentucky/Louisville");
  3. $lex = date("Y-m-d h:i:s A"); //Lexington, USA
  4. echo "Lex: ".date("Y-m-d h:i:s A")."\n\n";
  5.  
  6. date_default_timezone_set("Asia/Hong_Kong");
  7.  
  8. $cebu = date("Y-m-d h:i:s A"); //Cebu, Philippines
  9. echo "Cebu: ".date("Y-m-d h:i:s A")."\n\n";
  10.  
  11. echo (strtotime($cebu) - strtotime($lex))/3600 ." hours difference between the timezones";
  12. //3,600 seconds is 1 hour

List of suported timezones in PHP can be found here:
http://us2.php.net/manual/en/timezones.php

Hightlight a table row on click using jQuery

Filed Under (General) by Wenbert on 19-02-2008

Tagged Under : , ,

The scenario: Every time you click on a row, the row highlights. When you click on the highlighted row - remove the highlight.
The jQuery / Javascript code:

  1.  
  2. //highligths the clicked row
  3. function highlightrow(obj) {
  4.     if ($(obj).attr("style")==‘background-color: rgb(255, 255, 187);’ || $(obj).attr("style")==‘BACKGROUND-COLOR: #ffffbb’) {
  5.         $(obj).removeAttr("style");
  6.     } else {
  7.         $(obj).attr("style","background-color: #FFFFBB;");
  8.     }
  9. }
  10.  

And for the HTML Code:

  1.  
  2. ..rest of the HTML tags here…
  3. < tr onclick="highlightrow(this);" >
  4. ..rest of the HTML tags here…
  5.  

How to filter database inserts - HTML, Usernames, etc. in Zend Framwork

Filed Under (General) by Wenbert on 15-02-2008

Tagged Under : , ,

I woke up today thinking about how to handle strings when inserting to MySQL. What if the string I am trying to save into the database contains HTML characters? Let’s say you are using FCKEditor, how would you “generally” handle strings to be inserted into your database? Because when I think of it, I don’t have a quick answer. I have to test it around until satisfied with the output.

If I am too strict of what to save — then I would have problems outputting the HTML into the browser. Tables would be messed up and form elements would not work.

So, how do you filter different kinds of data to be inserted into MySQL using Zend Framework? Kinds of data as in:

  • Strings with HTML characters (mostly from a CMS form where it needs to render the HTML again)
  • usernames (no special characters)
  • passwords
  • what about encoding?

Update rows in Table A from values of Table B in MySQL

Filed Under (General) by Wenbert on 14-02-2008

Tagged Under :

Sometimes, we need to update values of tables from the values from another table. Here is an example:

  1.  
  2.         UPDATE `transactions` t , `tran_daily` daily
  3.         SET
  4.             t.col_manager   = daily.Col_manager,
  5.             t.invoice_date  = daily.Invoice_date,
  6.             t.due_date      = daily.Due_date,
  7.             t.po_no         = daily.Po_no,
  8.             t.remark        = daily.Remark,
  9.             t.gross_amount  = daily.Gross_amount,
  10.             t.adjustments   = daily.Adjustments,
  11.             t.open_amount   = daily.Open_amount,
  12.             t.bill_to       = daily.Bill_to
  13.  
  14.         WHERE
  15.             t.company       = daily.Company AND
  16.             t.trans_type    = daily.Trans_type AND
  17.             t.invoice_no    = daily.Invoice_no AND
  18.             t.line_no       = daily.Line_no

Cron job examples for newbies

Filed Under (General) by Wenbert on 12-02-2008

Tagged Under : ,

Here are a few examples from this site.

01 * * * * root echo "This command is run at one min past every hour"
17 8 * * * root echo "This command is run daily at 8:17 am"
17 20 * * * root echo "This command is run daily at 8:17 pm"
00 4 * * 0 root echo "This command is run at 4 am every Sunday"
* 4 * * Sun root echo "So is this"
42 4 1 * * root echo "This command is run 4:42 am every 1st of the month"
01 * 19 07 * root echo "This command is run hourly on the 19th of July"

Do a “crontab -e” on the shell. If you don’t have permission, try “sudo crontab -e”. It should open up Vi.

What is the safest way to do database queries in Zend Framework?

Filed Under (General) by Wenbert on 12-02-2008

Tagged Under : ,

I have no idea. You tell me. All I do is this:

  1.  
  2. $sql = "SELECT * FROM Table1 WHERE id=’".$target_id."’";  /*That is $target_id inside single-quotes in the SQL Query.*/
  3.  

Please share your thoughts below.

jQuery: Select all options in a Multiple-option Select Box

Filed Under (General) by Wenbert on 04-02-2008

Tagged Under : , ,

Alright, here is a quick example of how to use jQuery to select all of the items in a multiple-option select box.

//Javascript part assuming that you have already included jquery.js in your header
$(document).ready(function() {
    $("#select_all_col_managers").click(function() {
        $("#col_manager_list").each(function(){
            $("#col_manager_list option").attr("selected","selected"); });
    }) ;

    $("#unselect_all_col_managers").click(function() {
        $("#col_manager_list").each(function(){
            $("#col_manager_list option").removeAttr("selected"); });
    }) ;

});

and now for the HTML part…

Filter by Collection Manager:
< select class="select_multiple" id="col_manager_list" multiple="multiple" name="RTCLMG[]">
< option>Must Select One
< option> value="< ?=$value['col_manager']?>">< ?=$value['col_manager']?>        < / select>

    < a href="#" id="select_all_col_managers">Select All< / a> 
    < a href=”#” id=”unselect_all_col_managers”>Unselect All< / a> 

Please note that I am using Code Igniter with this.

All the Cheatsheets for Web Development in da World!

Filed Under (General) by Wenbert on 02-02-2008

Tagged Under : ,

A few weeks back, someone sent me an email.

Hi,

We just posted an article “The Cheat Sheet Cheat Sheet: Top 100 Lists of Web Development Cheat Sheets

( http://www.virtualhosting.com/blog/2008/the-cheat-sheet-cheat-sheet-top-100-lists-of-web-development-cheat-sheets/ )I thought I’d bring it to your attention just in case you think your readers would find it interesting.

Either way, thanks for your time!


Amy (snip-snip)

Why I hate Code Igniter (and why ZF FTW!)

Filed Under (General) by Wenbert on 01-02-2008

Tagged Under : ,

Here is a snippet from my code…

  1.  
  2. public function transaction($company_var=, $company_value=, $parent_var = , $parent_value=, $current_page=‘1′, $offset_value=)
  3.     {
  4.         $data = array();
  5.         //GET VARIABLES PASSED THRU FUNCTION
  6.         //I hate code igniter for this.
  7.         //I found out that you can have query strings later on :-(
  8.         //UPDATE:
  9.         //But then again, Code Igniter sux at handling queries in the URL
  10.         //I especially hate that you have to pass "variables" to the Method and not
  11.         //being to get the variables directly from the URL using $_GET
  12.         //WTF?!?! I have to enable query strings in the config file?
  13.         //Did they just DISABLE a feature in PHP?
  14.         //I AM NEVER GOING TO USE CODE IGNITER AGAIN. Zend Framework FTW!
  15.         //I nevarrr had this problem in ZF! Zend Framwork FTW (again)
  16.         $data[‘RTCO’]      = $company_value?$company_value:$_GET[‘RTCO’];  //Code Igniter is bullshit! I had to add this due to CI unable to $_GET properly!
  17.         $data[‘RTPA8′]     = $parent_value?$parent_value:$_GET[‘RTPA8′];   //Code Igniter is bullshit! I had to add this due to CI unable to $_GET properly!

While in my other method, i have this…

  1.  
  2. redirect(‘?c=customer&m=transaction&RTCO=’.$company_value.‘&RTPA8=’.$parent_value.‘&col_manager_selected=’.$data[‘page’][‘col_manager_selected’]);
  3.  
Subscribe to Rss Feed : Rss