WordPress pages load very slowly after Google is blocked

After Google is completely blocked in China since May 31, I’ve had problems loading my website. After some investigation I found out the problem lies in loading failure of Google Fonts. Since it takes a long time to fail, the page waits before it fails and display with the fallback styles.

To solve the problem, I crawled the font styles from Google and put it up on my server. Then I changed the WordPress theme to use the font style on the server. Everything seems to work perfectly after that.

Another option would be completely disable Google Font Styles. This can be easily done using the WP plugin “Disable Google Fonts”, if you’re using WP’s default twenty-* themes. In my case, I would have to comment out two lines in Mog Theem Functions file (functions.php). Since my theme relies on Google Fonts, instead of commenting out the lines, I changed these to lines to use the localized style file:

 

Fear makes one only weaker

Yesterday morning I received a call from one business partner complaining about two german students not satisfied with the internship position at another business partner in Changzhou. So we decided to drive to Changzhou in order to get a subjective grasp over the issue. And the issue was more serious than we have expected: neither of the two interns are satisfied with the placement, and one was in a very bad physical situation. Plus, he had lymphoma — a type of cancer — a few years ago and is still recovering from the treatment.

Strange thing was that he felt quite in Germany, but since he was pale and didn’t feel very well, we took him to the hospital for a check. We we arrived at the hospital, he couldn’t even stand up and we had to use a wheel chair to escort hime to the emergency treatment department, where the doctor checked his heart rate, body temperature, oxygen level, and a comprehensive blood test.

We looked very serious about his situation, but the doctor said everything was OK with him. She smiled and said to us in Chinese, “I believe he has hysteria”. I’ve heard about hysteria before but never really met someone with such symptoms. So I observed him carefully as the doctor give him a saline. One of my colleagues sat next to him and chatted with him. He seems extremely normal to me when he is not discussing about his illness or cancer. They constantly bursted into laughters when they talked about funny experiences, which is a bit weird since patients next to him are really seriously ill.

After confirming with the doctor again and again, we decided to go for dinner before the saline was finished and he seemed much better. We went to a german restaurant and had a really nice dinner. Over the dinner no one mentioned about his illness nor cancer. And he seemed totally fine.

This is really the first time I see how one’s mind may affect his physical state — in such a drastic way. That’s why when one is afraid of bad things, bad things always happen. Because fear of something makes one weaker, so that one does not have enough energy to defend oneself. This is another ‘scarcity’ problem: when you focus too much on something, you’re using too much bandwidth and leaving too little bandwidth for other things. And you’re trapped deeper and deeper until you are completed depleted of bandwidth or energy — that’s when you collapse.

The best way to fight this problem is to lose some focus on the fears. Then you’ll have more bandwidth to cope with other more important stuff. Just step back, ignore the fears for some time, and find out the long-term plans or goals. After all, not all in life are important, at least some are not any important as we’ve thought.

The lean method

I knew there was something wrong with the management and how we do things at Yabroad, but it was difficult for me to convince other people what we were doing and how we do things are not the best way to run a startup business. When I talk about pragmatism, people talk about visions and having a long-term goal; when I talk about experiments, people talk about previous experience; when I talk about planning and specific goals, people talk about execution. After reading “The lean startup” and “Running lean”, I’m more convinced about how a business should really operate.

The lean method is really about how to get things done efficiently, be it running a small project, or managing a international corporation. It’s about down-to-earth planning and taking advantage of resources efficiently. It’s a call for doing things that really matters. When proposing a new project, ask not if we think it’s cool, ask how we’re going to satisfy the end users. And the first step to go is really getting to know the actual users, what are the problems they find painful and how other products are approaching the problems, and why our proposal is better than the existing solutions.

We made a mistake at Yabroad that we think people are willing to come to China if we don’t charge them much. While our competitors are charging thousands of euros per application, we charge only a few hundred. But we didn’t see an exponential growth, the increase of applications was only negligible. We talked too much about disruptive innovation and thought lowering the price will piss out all our competitors and help us gain a portion of the market share rapidly. We were wrong.

The decision was made without much evidence to prove our assumption. Price is indeed an important factor when people want to visit a different country, but it’s not the deciding factor. Given the opportunity to visit North Korea or Iran, does it still matter if you want to pay thousands of euros or hundreds of euros? Our customers want security and reliability, lowering the price simply does not help, and let’s hope it doesn’t jeopardize customers’ trust in us.

We were not utilizing validated learning. In fact few of our decisions were made based on solid facts and validated results. Arrogant people often think they are the best in this world and they usually piss of everyone else and complain about “why everyone is against me?” Arrogant companies don’t get customers. What they do is not to satisfy customers, they just want to prove themselves correct.

The build-measure-learn loop should be continuous and iterate in fast pace. Build a minimum viable product and measure how successful it is and learn where it could be improved and improve the MVP and enter the next build-measure-learn loop. Validate minimal concepts at a time. Get the whole project running and receiving income before burning out what you have.

It’s true that starting up is really management — if you know where to put resources and man power, and keep track of the direction the business is running towards, you won’t be too wrong.

Raspberry Pi as a toy web server

1. Tell my router to route certain traffic to the Raspberry Pi. For example, I route HTTP and SSH traffic to one of my Pi’s. I disabled password login for  SSH, using public key authentication instead: in /etc/ssh/sshd_config, use the following setting and restart SSH service using `sudo service ssh restart’.

2. Getting my IP address of the Raspberry Pi. I firstly created a PHP script on my domain to record the IP address in a text file.

Then tell the Raspberry Pi to report its IP address every 5 minutes, using crontab:

After a while the IP address is recorded in the text file and updated every 5 minutes.

3. Optionally create a DNS record for the Pi. I use Cloudflare to manage DNS settings by myself, so just add/update an entry in Cloudflare’s settings. I point pi.daoyuan.li to the IP address of one Pi. This can be done automatically in the future.

4. Install Flask on the Pi.

5. Install nginx and uwsgi on the Pi.

6. Set up nginx along with uwsgi and Flask.

Edit nginx config:

Edit uwsgi config:

Create a simple Flask app:

Start up uwsgi:

7. Done! http://pi.daoyuan.li:5000/

 Update on June 24, 2014:

Getting the external address in step 2 can be done by running this command in Raspberry Pi:

See: http://www.commandlinefu.com/commands/view/5427/get-your-external-ip-address

What’s important for a start-up

A friend of mine is considering to set up a startup company , here are the things I think are important for startup. Usually when people think of a startup they think of new ideas. However I don’t think good ideas are so important. It’s not difficult to come across a good idea, but it is extremely difficult to get one idea realized. People usually don’t buy ideas, they pay for products and services. Besides, ideas can be easily copied, while its more difficult to copy the implementation of the idea. Furthermore, one can easily judge if one idea is novel or not, by comparing with current solutions; while it’s not so straight to claim one idea to be better than others. Ideas  solve problems and good ideas solve problems in a better way. However, before a problem is actually solved (that is when an idea is realized), ideas are nothing but plain wishful thinking.

I think the most valuable and important  thing for a startup company is the team. The team decides where the company is going towards, what the company is going to do, how they are going to do it and whom they are going to do business with and sell the product to. The team determines how fast company will move and turn and act. Since the only advantage of a startup company has over a large corporation is its fast decision making process and execution, the team is the deciding factor of a startup’s survival or death.

It doesn’t matter really if you have a good idea or not, as long as you have a good team and given some time, you definitely will come up with a fantastic idea. An ideal team for me would be something like this: everyone has his/her domain of expertise and others can completely rely on his/her capability of getting things done in his/her domain. Members in the team has slightly intersecting capabilities and as a team form the whole capability map. Someone brings everyone else together and keep everyone motivated and moving; someone is a technical guru and has the insight of solving problems efficiently; someone knows customers and is able to sell them everything he/she has in hand; someone is keen to budget control and at the same time knows where exactly to spend money; someone has extremely good relationships with the rest of the world. Members in the team does not have to agree with each other and they should be able to discuss or argue and reach a decision in a timely manner. They should have the insight into problems and the analytic skills to identify and prioritize tasks.

And still among the team the founders are even more important. They are really what the startup is. They give the startup a life if done correctly; or else the bad genes will follow the company forever. They are the startup’s creators, parents and baby-sitters. They should have the courage to risk everything they already possess for a glimmer hope of success. They believe and love what they are doing not because they don’t have other choices, but rather choose to not to have a choice. They believe they are doing the right thing and are willing to take responsibilities for what they are doing.

When people think of startups, people immediately think the ultimate goal for a company is to go public and get listed in major exchanges. That’s not startups’ goal. Companies need to make money. And founders need to consider this task from day one, if not day zero. Making money is not the same as getting funded by angel investors or venture capitalists. Getting funded is one way out of many to get the ideas recognized but not the ultimate goal. People fund startups because they think the companies are going to make a huge amount of profit. Making profits is about proving to the world that what the startup does is meaningful. What’s the point of keeping burning cash anyway?

When big companies like Google and Facebook purchase small or startup companies, what they’re really buying is the customers, the technologies, and the talents. And among these three, talents are the most important to me, since without the talents the customers and technologies will be found nowhere. In short, you’re destined to success or failure the day you choose the team members for your startup.

NumPy’s ndarray indexing

In NumPy a new kind of array is provided: n-dimensional array or ndarray. It’s usually fixed-sized and accepts items of the same type and size. For example, to define a 2×3 matrix:

When indexing ndarray, it supports “array indexing” other than single element indexing.  (See http://docs.scipy.org/doc/numpy/user/basics.indexing.html)

It is possible to index arrays with other arrays for the purposes of selecting lists of values out of arrays into new arrays. There are two different ways of accomplishing this. One uses one or more arrays of index values. The other involves giving a boolean array of the proper shape to indicate the values to be selected. Index arrays are a very powerful tool that allow one to avoid looping over individual elements in arrays and thus greatly improve performance.

So you basically can do the following:

Besides, when you do equals operation on ndarrays, another ndarray is returned by comparing each element:

Statistics of insurance sold on Taobao.com on Valentine’s Day

On Feb. 14th Taobao launched a campaign to sell insurance products, which promises 7% yearly interest rate. The sales data is public, so I wrote a script to crawl them down and did a brief study on this data. Here’re the results.

On that day (actually sold out in less than two hours in total) more than 40,000 people participated, resulting a total sales of almost one billion CNY (the exact number: 980,270,000 CNY). Two companies participated in this sales campaign: Zhujiang and Tian’an. The sales statistics are:

Zhujiang Tian’an Total
# of Customers 13831 29092 42923
Sales mean (k CNY) 24.922059 21.847003 22.837872
Sales min (k CNY) 1 1 1
Sales 25% (k CNY) 1 2 2
Sales 50% (k CNY) 10 10 10
Sales 75% (k CNY) 20 25 22
Sales max (k CNY) 1000 900 1000
Sales total (k CNY) 344697 635573 980270

The histograms of how many people pay for each amount.

le100kgt100kle100k

Zhujiang was extremely popular: in 2 minutes and 56 seconds it reached a sales of 200,212,000 CNY, that’s more than 1 million CNY sales PER SECOND! Indeed Chinese are crazy about online shopping. 😀

MapReduce in MongoDB

http://docs.mongodb.org/manual/core/map-reduce/

http://docs.mongodb.org/manual/reference/command/mapReduce/

The MapReduce code I used to analyze the 20 million hotel reservation records:

 

The Last Battle: Long-term vs. Short-term Gains

During yesterday’s meeting the boss mentioned that our unpaid salary and bonus will be paid, when we have enough money, maybe in April when we receive the other half of high interest loan. Personally I don’t think paying the money will do any good to the company, and eventually it may harm ourselves, since if the company can not move on, everyone, including me, will be disappointed. However, as I’m involved in this, I’m not willing to give up the money I’m supposed to receive. And asking for the money will make me look like as if I don’t care about the company and everyone else’s future, especially when I’m the one speaking out for a few of us. So now I’m caught in a dilemma: I’m not willing to give up the potential short term benefits, which in turn may jeopardize my long term gains.

And the reason for this is that I’m different from others; I care about short-term gains while others can afford not to. And that’s why I feel helpless. I can not expect anyone to help me get things done; I’m on my own. And even if I stand up for myself and gain some short-term benefits for others, they will accept them without appreciating my efforts.

I’m completely trapped, by myself, with my colleagues’ help of standing away from me — neither stopping nor encouraging me and neither refusing nor appreciating my favor — and I didn’t even know how I entered the trap in the first place.

The Last Battle: My Fear

The day we reach an agreement to cut off employees was not a difficult day for me, as I always knew there would be a day like that coming; I was prepared. In the evening when I was talking with Xin, he said he feared not being able to reach the goal when planned during the day, which I fear not. What I fear was returning to the old pattern again, the patten that make the boss keep trying to find funding for us without actually focusing on how to achieve our established goals. I was afraid that he keeps borrowing money to pay off previous debts, while we struggle to reach our goals. I was worried that the boss prioritize fund raising over proving our values.

Yesterday came a challenge: the local government finally seemed to approve one of our projects: letting us operating a part of one restaurant building inside our community, which means we can again get loans from banks with relatively low interest rate. The boss hesitated. According to Xin, the boss wondered if it’s still necessary to lay off people.

Now it looks like the boss has overcome his reluctancy. He finally sent out an email telling everyone about our plan. What remains to be seen, though, is how the restaurant operates in the future and whether it could bring us profit. And even if it does, does it help us?

The boss has one thing I could learn from: he sure knows how to connect with people and never gives up unless he reaches his goals. As for the many things that I contempt about, there’re many.

He never listens to anyone. He is so dedicated to his own thoughts that nobody seems to be able to change his mind. Talking with him is of no use; he likes reading from elsewhere. Yesterday I was irritated by him when he shared something he read about and it was about things we already mentioned to him earlier for several times. A man who trust his eyes more than his ears, I’d say.

He is over-confident about almost everything. He always overcommit. I don’t know a single occasion when he reach his goals or fulfilled his commitments.

He has many things I couldn’t bear with, but what the heck I’m doing with him?

The Last Battle: Our Problems

After yesterday’s 6-hour meeting we finally made a decision: focus on programs that may immediately make money and make sure we survive in the following six month; and cut off more than half of our employees — which makes me think what a pity it is for those being laid off, because it’s mainly the executives’ fault. Or to be specific, it’s the boss’s problem that lead to the current situation.

So what he is doing wrong? Not focusing on the business. Since day zero he is always looking for fundings to support our business, which he fails to define; but he always fails to find enough funding to support the company. Each borrowing was used to pay previous debts, which leads to a situation defined in the book “Scarcity”: the poor gets poorer, the busy gets busier. We are always solving problems that are urgent but not necessarily important — we tunnel and we pay for doing this.

But what’s important anyway, for a startup? Finding out what’s unique about your company and proving that this uniqueness has its value. It sounds easy but think about this: is there a startup that isn’t unique. Every startup claims to be unique; so what’s left is about proving the value of the uniqueness, which is your core business activity and which is what tells you apart from others. If you fails doing so, what you’re doing must be wrong or inappropriate at best. For us, we claim that our business model is superior than those traditional agencies and facilitates young people to travel beyond boards. The results? For one and half years we spent roughly 5 million CNY and attracted around ten customers, which by the way, is less than the number of our employees. So if you keep telling me you’re unique, go and slap yourself until you realize you’re just wasting money.

To prove your value you need the right team. There has to be salesmen that are able to get customers, product developers that make sure the product or service is attractive, and managers to setup goals and coordinate the team members. For us, we are incomplete and incompetent. Basically everyone of us is from an engineering background and knows nothing about marketing and sales; yet this is the most important aspect for our company. When everyone is expecting others to generate revenue, no one will. It also strikes me that, when you feel your efforts will not significantly contribute to your company’s cash flow, you’re in the wrong place. Switch to another position or another company. I don’t think there’re more choices for you.

Make sure you have control over your career path; do not focus too much on pressing tasks; step out of the tunnel and also see the big picture. Keep this in mind.

Debugging Apache configuration files on Mac OS X

Sometimes I make some modification to my site’s apache config and apache stops functioning, but I cannot get enough information from /var/log/apache2/error.log. Here’s a command that will tell you where the problem is:

It starts apache for debugging and prints out the messages on screen, so that hopefully you can find something useful.

mod_wsgi and mod_xsendfile on OS X 10.9 Mavericks

Updated on Nov 4, 2013: The following tricks may still work, however I have found a much easier solution. Simply install Xcode command line developer tools and you should be able to compile source code without issues:

After upgrading my Mac from 10.8 to 10.9 Mavericks my apache stopped working, so I have to reinstall mod_wsgi and mod_xsendfile. However, tricks are needed to compile and install these mods successfully.

Upgrade Xcode

Upgrade Xcode in App Store. As mentioned by Valerie:

I had to manually upgrade Xcode (after Mavericks upgrade) from the App Store & agree to its license because ./configure hung forever until I did that.

mod_wsgi

For mod_wsgi installation, create a soft link to OSX10.9.xctoolchain:

Then run configure under mod_wsgi source code directory:

It will generate a Makefile similar as follows:

However, this Makefile is not correct and running ‘make’ the compiler will complain something like:

Prepend the following line to CPPFLAGS value:

Save the Makefile and it will look something like:

Then make && install:

Modify /etc/apache2/httpd.conf to enable mod_wsgi:

mod_xsendfile

Use the following command to compile and install mod_xsendfile:

Enabling HTTPS/SSL

After upgrading OS X the apache configuration was reset, but your original config is save to /etc/apache2/httpd.conf.pre-update. I need to enable SSL in httpd.conf again by uncommenting the following line:

Restart Apache and everything should work fine

Solution: dd too slow on Mac OS X

When I was cloning SD cards on Mac OS X using dd', it takes ages to get things done. I was using the following command:

It takes much less time when using /dev/rdisk2 instead of /dev/disk2:

The reason is that rdisks are "raw" thus resulting in a higher R/W speed, according to man hdiutil` [1]:

/dev/rdisk nodes are character-special devices, but are “raw” in the BSD sense and force block-aligned I/O. They are closer to the physical disk than the buffer cache. /dev/disk nodes, on the other hand, are buffered block-special devices and are used primarily by the kernel’s filesystem code.

[1] http://superuser.com/questions/631592/mac-osx-why-is-dev-rdisk-20-times-faster-than-dev-disk