# How to Translate Apache’s “RewriteRule” Into Nginx’s “Rewrite”

| Comments

There are many cases you need to use friendly url. If you are using Apache, tipcially you can activate the URL rewriting module and write some rewriting rules with .htaccess file; While if you are using Nginx, you can also write some rewriting rules. Both of them support regular expression, so it’s easy to translate from one to the other.

To translate from the Apache’s rewriting rule to the Nginx’s, simply do the following substitutions:

# Adaptive Color Selector

| Comments

This is an adaptive color selector. It can dynamically choose which color of checkmark to use. When a light color is chosen, a black checkmark display; while when dark color is chosen, a white checkmark display.

Here is a screenshot.

# Replace Strings for All Files in a Folder

| Comments

In my previous blog, I wrote the code to replace all string in a file: http://leons.im/2011/02/replace-all-strings-in-a-file/. Today, I write a cooler code – It can replace all strings in many files, actually it can replace all strings in files that are in a same folder.

# Always “Clear” the “Float”

| Comments

Unless you really want to use Block Formatting Context, it’s usually a good idea to clear the float.

# Nginx 502 Bad Request

| Comments

I have got this error many times. Today, I dived into it and resolved it.

I use php-fpm and nginx on my server. Occasionally, I got 502 bad request error. When I check the nginx log, it says upstream sent too big header. In my memory, the default buffer size if big enough. To make sure it’s not caused by this, I add the following lines to the nginx configuration file:

# My Certificates for CS101 and CS373 @ Udacity

| Comments

I received Certificate of Accomplishment with Highest Distinction, which the highest level of certificates, from Udacity for both CS101 (Introduction To Computer Science - Building A Search Engine) and CS373 (Programming a Robotic Car).

# PID Control

| Comments

When I was a college student, I participated a contest of mathimatical model. It’s a physical problem, which I didn’t find the model to solve. While I am studying the Udacity’s class Progamming a Robotic Car, and when it comes to PID control, it occurs to me that it’s the model exactly to solve the contest’s problem!

PID control is really an interesting and excellent algorithm. The detail information can be found at Wikipedia. The main point is that the control system has 3 parts: the Proportional, the Integral and the Derivative.

The formular is:

$$u(t) = MV(t) = K_pe(t)+K_i\int_0^t \! {e(\tau) \, \mathrm{d}\tau}+K_d\dfrac{d}{dt}e(t)$$

# Python Script for Getting a Random Address With Google Map API

| Comments

With Google Map API, you can do a lot of thing. Here I will use it to turn latitude and longitude into human-readable addresses.

# Python Code for Counting LOC(Lines of Code)

| Comments

Before I know CLOC, SourceCounter or Ohcount, I write this script.

# Vimrc

| Comments

I’m using vim while still using emacs.

Just record my .vimrc file here.

# Pyramid + Nginx + uWSGI + MySQL

| Comments

This article describes how to set an development and production environment for Pyramid web framework on a Linux platform with Nginx, uWSGI and MySQL.

# Do Not Use Inline-block in CSS (Obsolete)

| Comments

UPDATE: As Vensires mentions in the comment, this post is obsolete.

Usually, when we want to arrange some blocks horizontally with CSS, we may choose to use float: left; property, or display: inline-block; alternatively.

According to http://www.quirksmode.org/css/display.html, inline-block is not supported by IE 5.5 and it’s not completely supported by IE 6 and IE 7.

# Anti-Debug With Trap Flag Register

| Comments

Let’s play an interesting Crack-memuckis’s crackme #2.

When you run the crack-me with a debugger, say OllyDbg, the program pops up a message box saying “What the hell are you doing in my app with a debugger?” and then exists, but when you run the crack-me without a debugger, just double-click on it, it runs normally.

# My First Keygen

| Comments

Recently, I’m reading pediy’s book: Encryption and Decryption. This is a really good book with many practical technologies and skills, and it’s also very interesting. In Chapter 2, I met a problem, so I cracked the demo crack-me program with ollydbg, but I’m not satisfied with that, so I studied the encrytion algorithm and wrote a keygen program.

The main algorithm is very simple, but it took me a lot of time to deal with the multi-byte characters problems, and I found there is another defination of unicode on Microsoft’s platform! I can’t figure out why Micro\$oft didn’t use UTF-8 to build his system just like Macintosh, because with UTF-8, we programmers don’t have to deal with these troubles at all. Anyway, Windows is such a snorty that most people still have to use it.

# SSH Login Without Password

| Comments

Why must login without password? Because it saves time and automizes tasks.

# A Simple Implementation of Solving Sudoku

| Comments

Sudoku is a popular game. Howerver, solving Sudoku is sometimes not so easy, so I wrote a program to help me do this job.

# Configure PHP-FPM and Nginx in Low Memory Servers

| Comments

Recently, I registered an Amazon EC2, ie Elastic Compute Cloud, with a free tier for the first year. The machine has only 600M memory. That is so few that it took me a few days to optimize my configuration files to make my blog and other web service run on this machine.

Before I use EC2, my blog is based on LAMP(Linux, Apache, MySQL, PHP). I decided to replace it with LNMP(Linux, Nginx, MySQL, PHP), since Nginx is said to be more efficient than Apache. To install all these is simple:

# How to Solve Broken Pipe Message in SSH Session

| Comments

Sometimes my SSH session disconnects with a Write failed: Broken pipe message. What does it mean? And how can I keep my session open?

It’s possible that your server closes connections that are idle for too long. You can update either your client (ServerAliveInterval) or your server (ClientAliveInterval).

# Send Email With PHP in UTF-8

| Comments

In my previous article Configure Mail Service with PHP Mail Function and Postfix, I described how to set up an environment to send mail with php on Linux.

Here, I will solve an issue which met by a lot of people, confused but don’t know how to do: How to send mail in UTF-8? Here I will tell you how to send an email with not only a UTF-8 subject but also a UTF-8 content. It’s simple. Just read the following code. Quote your subject with '=?UTF-8?B?' and '?='. You may choose to use HTML to edit your email content, just don’t forget to declare UTF-8 character set. That’s all.

# Configure Mail Service With PHP Mail Function and Postfix

| Comments

This article describes how to use the php function mail to send a mail.