Starting C++ control structures

Well we all know control structures are basically if, if/else, while, do, switch, and a few other methods that you can use to specify a sequences of task that the program may carries out.
I started reading the How to Program C++ book, a gift from my teacher. The book is a college level, well-written, even though it is quite old, published in 1998. But the detail it contained was amazing...
Just a few quick notes on control structures:

1. algorithms - a procedure for solving a problem
2. pseudocode - plain-English statements that allow a programmer to develop algorithms
3. total of only 7 control structures
[1] sequence
[2] selections -> if, if/else, switch
[3] repetition -> while, do/while, for
4. it's always good to initialize counter and total to zero
5. counter = 1;
6. counter =0;
7. conditional operator -> (?:)
8. counter-control-structure = definite repetition
9. sentinel-control-structure = indefinite repetition
10. use top-down, stepwise refinement to develop the algorithms

日文作弊風波

星期一回來偷了日文課的考試, 拍了照片之後放到facebook
tag了大約8-9個同學, 不過差不多全班同學都知道這件事, 大家都上網看了這份試卷
雖然沒有考到100不過成績還是算可以的

本來星期二考試以後有打算去deleted, 不過我實在是太懶了
後來今天終於被學校發現, 大概是有人舉報了
本來要停課5天, 不過後來給了機會, 說不用了

不過我最煩惱的是兩件事
1) 明天回去怎麼面對日文老師? 以後的成績又如何?
2) 以後要cheat更不可能, 本來她其實也不介意我們作弊, 現在連卷都給偷了, 以後就更不用說是考試時作弊啦

看來明天是黑色星期五

這星期到底都做了什麼?

Good question...我想沒什麼...就是整天對著電腦。
看看, 連AP Calc和COMPASS MATH 3 都沒有準備-.-"
功課明天一定要做了....

今天花了整天時間要去幫alan888的一個會員轉換論壇
靠, 失敗了...
不多說, 大家可以來看這邊
http://gokoproject.com/wp/programming/2009/02/20/upgrading-60-to-70-failed/

對了, 這個是我的programming blog
anyway....
嗯... 很無聊的一天

最近在追包青天和royal trump =3=
晚上有時候會陪家人看同事三分親... 好像比起 畢打自己人更好, 可能還是 原裝的比較有勁!!!
星期天要去CCNY面試...呼~

upgrading 6.0 to 7.0 - Failed

Yeah, I decided to help this member out. I thought her case would be a easy task but unfortunately, since I really don't have much experience with the latest discuz upgrade, I probably just made myself into a dead corner.

Now the failure didn't start with me, when I checked the database lately.
It looked like her attempt in upgrading 6.0 to 7.0 was the actualy cause of this failure because no matter how hard i tried to hack back the missing value, they just didn't work out.

The upgrade theory is always the same, nothing big deal. I can no longer upgrade it from 6.0 to 7.0, as I ran the db60to70.php. I didn't know how many times I tried to make the tool not to recongize the version first....but oh well

I don't know. I also accidentlly deleted her directory. The good thing is, I did backup her database, and the template files. She only lost two things, 1) some of the imgs, and 2) the index modifications she made in the past.

What a shameful thing in my eyes.... I never expect such a result.
Now I really need to think in a different way, to make her 6.0 upgradeable. You know, the left over solutions are, either find another expert to help her out (highly experience with discuz), or I have to try again, get 6.0 into 7.0 database right away, and run the database upgrade once I import it. But this is what I did for the whole day...

Goosh...

Discuz6.0 - remove one of the hide option

So I came across with this problem before I went to bed. I took 20 minute trying to help this member help.
Eventually the modification worked out.
Here is the thread
能否去掉 隱藏按鍵 積分文字去除問題

Hmm. so initially I went to include/javascript/editor.js and removed this line

Find

1
                str += cmd == 'hide' ? '<input type="radio" name="' + ctrlid + '_radio" id="' + ctrlid + '_radio_1" checked="checked"/>只有當瀏覽者回復本帖時才顯示<br /><input type="radio" name="' + ctrlid + '_radio" id="' + ctrlid + '_radio_2"/>只有當瀏覽者積分高於 <input type="text" size="3" id="' + ctrlid + '_param_2"/> 時才顯示' : '';

Replaced with

1
                str += cmd == 'hide' ? '<input type="radio" name="' + ctrlid + '_radio" id="' + ctrlid + '_radio_1" checked="checked"/>只有當瀏覽者回復本帖時才顯示' : '';

It didn't work out at all. The member reported it and said he couldn't insert the hide tag anymore. I checked the source and thought I was missing something there.
The first attempt was to not to remove the 2nd input value. Just leave it there. So only the button remained, but it looked ugly.

I wanted to remove the 2nd input completely from this js source code. I thought this would be a robust modification. Now, I checked the source carefully. I realized this hide tag, has two sections:
[1] the first section is what I modify. It is the input make-up, has little to do with the actual insertion.
[2] the code below it is a function. It controls how the tag will be insert.

So i am on the right path......

(more...)

MySQL: converting to UTF-8

It's possible to convert anything today. Hmm, this is not a new thing. But one of the major problem is people get lazy to alter every database table themselves.

First of all, let say you want to convert from big5_chinese_ci to utf8_general_ci, that's pretty easy in theory.
But you need at least two software to help you to edit the sql file.

[1] Export your database via phpmyadmin, and download it as an sql file format.
[2] Get an editor like EmEditor, open the sql, edit it, by replacing all the charset with utf8, be careful, some of them need to be replace as utf8_general_ci, some just utf8. scroll down and replace them, and in the end save it as utf8
[3] now, install your application again, in UTF-8 version.
[4] drop all the tables
[5] finally, import the original sql file (which is now utf8 after saving it), into phpmyadmin
[6] you need a script to alter the table, save it, name it as convert.php, and upload it to your root
[7] edit the database information in the convert.php, just the database information
[8] run the convert.php on your browser, copy and paste the code it generates.
[9] go to phpmyadmin , select that database, and go to SQL, and copy and paste, press ok to run the action
[10] in theory, if you did the editing correct in step [2], once you run those SQL queries, they will fail because all the tables are already collated in utf8_general_ci format.

This is just a theory on how to convert from one collation encode to UTF8.
I will always suggest you do utf8_general_ci, because it takes less resources, and is better with mutli-lang, and it;s generally faster than utf8_bin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
// original script (v1.0) by/from: http://www.phpwact.org/php/i18n/utf-8/mysql
// improved/modified (v1.03) by Bogdan http://bogdan.org.ua/
// this script will output all queries needed to change all fields/tables to a different collation
// it is HIGHLY suggested you take a MySQL dump/backup prior to running any of the generated queries
// this code is provided AS IS and without any warranty
set_time_limit(0);
// collation you want to change to:
$convert_to   = 'utf8_general_ci';
// character set of new collation:
$character_set= 'utf8';
// DB login information - *modify before use*
$username = 'database-user-name';
$password = 'database-password';
$database = 'database-name';
$host    = 'localhost';
//-- usually, there is nothing to modify below this line --//
// show TABLE alteration queries?
$show_alter_table = true;
// show FIELD alteration queries?
$show_alter_field = true;
mysql_connect($host, $username, $password);
mysql_select_db($database);
$rs_tables = mysql_query(" SHOW TABLES ") or die(mysql_error());
print '<pre>';
while ($row_tables = mysql_fetch_row($rs_tables)) {
    $table = mysql_real_escape_string($row_tables[0]);
    // Alter table collation
    // ALTER TABLE `account` DEFAULT CHARACTER SET utf8
    if ($show_alter_table)
        echo("ALTER TABLE `$table` DEFAULT CHARACTER SET $character_set;\r\n");
    $rs = mysql_query(" SHOW FULL FIELDS FROM `$table` ") or die(mysql_error());
    while ( $row = mysql_fetch_assoc($rs) ) {
        if ( $row['Collation'] == '' || $row['Collation'] == $convert_to )
            continue;
        // Is the field allowed to be null?
        if ( $row['Null'] == 'YES' )
            $nullable = ' NULL ';
        else
            $nullable = ' NOT NULL';
        // Does the field default to null, a string, or nothing?
        if ( $row['Default'] === NULL )
            $default = " DEFAULT NULL";
        elseif ( $row['Default'] != '' )
            $default = " DEFAULT '".mysql_real_escape_string($row['Default'])."'";
        else
            $default = '';
        // Alter field collation:
        // ALTER TABLE `tab` CHANGE `fiel` `fiel` CHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
        if ($show_alter_field) {
            $field = mysql_real_escape_string($row['Field']);
            echo "ALTER TABLE `$table` CHANGE `$field` `$field` $row[Type] CHARACTER SET $character_set COLLATE $convert_to $nullable $default; \r\n";
        }
    }
}
?>

Advanced Points System for phpBB3 (clean up for v0.8.2) - Part 1

Since I am working on a mod-packed phpBB, so I came across with this modification developed by Adrian.
The modification homepage is here:
http://phpbbgods.org/index.php

I am not the author of this mod. Adrian is the author.

So, this is a great mod but there are so many things that the author needs to clean up before moving to the next version.
There are three major problems:

[1] The subsilver2 template, many minor changes, or outdated advanced points system add-on.
[2] The language files which will also link to the issue with the outdated subsilver2
[3] The transfer system in version 0.8.2 should upgrade

Let me get this started.
The major problem with the subsilver2 template is that, adrian, probably too busy with fixing the php content of the code (the core), didn't remember to re-code the subsilver2.

Some of the add-on template conde in subsilver2 are outdated. For example:

Open Points\root\styles\subsilver2\template\points_bank.html

1
 Options

(more...)

Remove the stupid wordpress html filter

Yeah, if you are really upset about the html filter by wordpress, this is what you want, then you are reading the right entry.

So i searched around and finally I got some other articles complaining about this.
There are two reasons why i need to stop the filter

1) it filters my < and > tags, so they won't appear in my highlight code tag
instead, you will see #include , not #include
2) it's annoying, i don't like dealing with it

so here is the solution

[ 1]open up wp-include/kses.php
Find

1
2
3
4
    // Post filtering
    add_filter('content_save_pre', 'wp_filter_post_kses');
    add_filter('excerpt_save_pre', 'wp_filter_post_kses');
    add_filter('content_filtered_save_pre', 'wp_filter_post_kses');

Replace with

1
2
3
4
5
6
7
8
9
10
    // Post filtering
    // add_filter('content_save_pre', 'wp_filter_post_kses');
     add_filter('excerpt_save_pre', 'wp_filter_post_kses');
    // add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}

function disable_kses_content() {
remove_filter('content_save_pre', 'wp_filter_post_kses');
}
add_action('init','disable_kses_content',20);

[2] finally, you need to download this plugin
Quotmarks Replacer

http://sparanoid.com/archive/wordpress/quotmarks-replacer/

You will need it, trust me, to disable those annoying special character filters.

another fun c++ program

It's just for fun, i will integrate a similar one into my hello world program :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Let me trying to run another calculation program
// no more salary now
// let gets this people vs bandwidth

#include <iostream>
using namespace std;

// let us do a gloabl variables

   int visitorNumber, visitBotNumber, bandwidth, dataSize, transferTime;
   signed int dataBWR = 4;

// let us begin the main body of this program

int main()
    {
          // asks some questions
          int x;
          cout << "How many visitors so far?\n"<< endl;
          cin >> x;
          cin.get();

          int y;
          cout << "How many bot visitors?\n"<< endl;
          cin >> y;
          cin.get();

          int z;
          cout << "What is the total amount of data size being uploaded?\n"<< endl;
          cin >> z;
          if (z >10000)
             bandwidth = (x + y) + (dataBWR * z);
          else
              bandwidth = (x + y) * (dataBWR);
          cin.get();
          cout << bandwidth;
          cin.get();
          return 0;
    }

這幾天都在忙著無聊事

哈哈這幾天都在忙著一些大概是無聊的事情
比如說這兩天在忙著做 mod-packed phpbb3
再前兩天在忙wp/store和cart的事
還有已經setup了 programming和senior proejct兩個blogs
嘿, 真的很無聊!!!

Page 1 of 212»