Fixing Chinese Garbled Text in Code::Blocks

Code::Blocks is a C/C++ IDE that I personally like to use, but I kept running into one problem: with Code::Blocks, I couldn’t use Chinese at all. Strings couldn’t contain Chinese, and even comments couldn’t. I originally thought it was a bug in the program itself, but a fellow user reminded me that it was actually a default encoding issue! ...

September 3, 2011 · 1 min

[C++] Sorting with the STL's Built-in sort() Function!

Sorting is something everyone who learns programming has to master, because a lot of data processing depends on it. Many programming languages include sorting functions built in, so developers can use them easily. But I don’t think many people know that C++ also has a built-in sorting function! ...

August 25, 2011 · 2 min

Zen Coding: A Great Tool for Speedy Web Development, a Must-Have for Anyone Who Likes Hand-Writing Web Pages~

I think many people are like me: when building a web page, they don’t like dragging out the layout directly in DW, and instead prefer to open Notepad and write the HTML by hand~ The upside of this approach is that it sharpens your skills XD, but the downside is that development is a bit slow (actually, once you get used to working this way, you’re faster than you would be with DW… XD). Today I want to introduce Zen Coding to you — it can make you write web pages N times faster! You can write web pages directly using CSS-style syntax~ ...

August 22, 2011 · 2 min

[PHP] Listing Files in a Folder with glob, scandir, and readdir

Sometimes you need to write a PHP program that gets a list of the files in a specified folder. For example, I needed this feature when I was making an online hard drive program. Here I’ll introduce three functions that can all do this, though each is used a bit differently: glob, scandir, and readdir. ...

August 17, 2011 · 2 min

Why Does My Visual Studio UI Look Different After Compiling?

This is a problem I ran into recently while coding. If you also develop with Visual Studio and have run into a similar issue, where the UI design in VS and the result you get when running the program don’t match, I recommend checking out my fix. It’s a bit silly, but it works well XD ...

August 10, 2011 · 2 min

Changing PHP's Execution Time Limit to Keep Long-Running Scripts from Being Stopped

By default, PHP has a 30-second execution limit. When a program runs longer than 30 seconds, you get an error like this: “Fatal error: Maximum execution time of 30 seconds exceeded”. This is a safeguard against bugs, such as infinite loops or other strange code that could end up bringing the system down. However, sometimes your program really needs to run for more than 30 seconds. For example, you might be processing a very large file in PHP, such as a database backup that can be hundreds of MB, which takes a long time and can easily exceed 30 seconds. My earlier Plurk BOT and spider programs also ran into this easily. Here I’ll show you two ways to adjust this time limit. ...

August 9, 2011 · 2 min

How to Defend Against Basic SQL Injection in PHP?

For the past few days I’ve been writing a small program to organize contacts, so I’ve been researching quite a few things. While working on the database side, I wanted to guard against so-called SQL injection, where a malicious string is placed in a parameter to attack the database. So I applied some basic defenses. The following is how to add some basic protection against SQL injection~ ...

August 2, 2011 · 3 min

How to Embed Arrays, $_POST, and $_GET Directly in a PHP String (SQL Query)

Over the past few days, while writing a small program, I ran into a problem. I wanted to put a $_POST variable directly into my SQL query string instead of using the concatenation operator. But because of quoting issues, it took me quite a while to figure out how. Here is a brief introduction. I also want to thank Bu and Cang Shixian for teaching me this method! If it weren’t for them, I might still not know about it. Also, this method isn’t limited to $_POST; it works with other arrays too. ...

August 1, 2011 · 2 min

How to Compute an MD5 Hash in VB.NET (System.Security.Cryptography)

Recently I was writing a password generator and needed to compute an MD5 hash. In PHP I can just call md5() to get an MD5 hash, but I had never actually tried MD5 in VB. I was worried that .NET might not have any MD5 support, in which case I would have to write it myself…. Orz. Luckily, when I checked MSDN, it turned out to be there. The process was a bit of a hassle, but fortunately MSDN provides a getMD5hash function, so I simply reused it. ...

July 26, 2011 · 2 min

Solving Pascal's Triangle with a Formula! (Thanks to Cang Hai)

The image above is from Wikipedia and is used to explain Pascal’s triangle. Today’s topic is the so-called Pascal’s triangle. Some people also call it Yang Hui’s triangle or Jia Xian’s triangle. The first row’s first entry is “1”. Each number below equals the sum of the number to its upper left and the number to its upper right. If there is no number to the upper left or upper right, it counts as 0. For example, the second row has two numbers, “1, 1”. The third row is “1, 2, 1”. And this triangle can extend infinitely. ...

July 24, 2011 · 2 min