A tale of serving static blog contents

I remember reading from somewhere (probably Twitter) that running WordPress is an open invitation for hackers to take control of your server. This blog was running on WordPress since 2010, and many things have changed over the years. I am no longer writing blogs furiously (like one blog post per day circa 2010). In fact my last blog post was in Feb 2019, more than a year ago. I also no longer need any advanced feature of WordPress anymore like users sign up or comments (both are open invitation to spam).

Dual-booting Windows 10/Ubuntu 18

It’s 2019 and dual-booting Windows/Linux is still not an easy feast! Ever since I moved to Apple ecosystem few years ago, I used Mac exclusively for desktops and Linux exclusively for servers and therefore don’t ever feel the need to touch a Windows machine. However recently I found myself occasionally need to have access to a Windows machine to upgrade firmwares, play games and stuffs. So with my Intel NUC, the obvious choice would be to dual-boot between Windows and Linux.

DigitalOcean credit expiration policy changed

Yesterday I received a strange email from DigitalOcean: Honestly, I don’t think it’s a good idea at all. Basically they want to change the expiration policy of ALL new and issued credits. You will have a month to use all your remaining credits, or it will be expired. It would be much better if they only add expiration for newly issued credits. As in, older credits will be kept intact.

Healthy Competition for Bitcoin

I’ve been following the Bitcoin block size debate since Gavin’s 20mb block proposal. If you’re not familiar with the block size debate, this wiki article is a good start. During the debate, I’ve lost respect for quite a few of famous people. But let’s put it aside. Let’s talk about a healthy competition for Bitcoin. There should be more than one teams working on different implementation of Bitcoin Yes, both the software and the protocol.

Goodbye Dropbox. Hello Google Drive!

Yep, that’s right. I finally made the switch from Dropbox to Google Drive. Dropbox is great. They have awesome and intuitive UI, and still the best UI among competitors so far. Their file sync process is simple but admirable. Instead of syncing the whole changed file, they only sync the difference. Reduce lots of network bandwidth and syncing time. So why the switch? Storage is the biggest issue. Even with edu accounts and lots of extra storage for completing Dropquests, my Dropbox limit is still far less than I need.

What I’ve learned this week: Dropbox, Spark and more

1. Dropbox Dropbox is shutting down its two apps: Mailbox and Carousel. I’ve been using both apps heavily recently. The most important feature of Mailbox is auto-swipe. Other competitors also have similar features, but they require much more effort to setup, while Mailbox only requires tap and hold. Easy like a piece of cake. Auto-swipe saves me from going through 14k+ emails so far. Carousel saved me lots of iPhone space by uploading my photos to Dropbox.

Du học: Ở hay về? (Ném đá ao bèo)

Quan điểm của mình là: Nếu không bị vướng bận về mặt tài chính (đi theo học bổng của nhà nước hay một công ty nào đấy và trong điều khoản có ghi rõ là sau khi học xong phải về) thì du học sinh muốn ở đâu thì ở. Khoan nói đến chuyện lòng yêu nước, cống hiến cho đất nước, bla bla bla, khi mà bạn còn chưa nuôi nổi chính bản thân mình (hoặc gia đình nhỏ của mình) thì cống hiến cái nỗi gì.

What I’ve learned this week: Let’s Encrypt, Python’s lambda and more

It’s never too late to start a tradition. I haven’t been writing blogs lately. 1. Let’s Encrypt In the ideal world, everyone should be able to do anything without the fear of eavesdropping. 10 years ago, it would be very hard to do this. Personal Computers were not very strong and Internet was slow, therefore HTTPS is reasonably slower than HTTP. Things have been changed. Computers are faster now. Internet speed has been increased exponentially.

Kepler-452b và Lược sử thời gian

Hôm qua NASA công bố tìm ra một hành tinh gần giống với trái đất, chỉ tiếc là cách trái đất những 1400 năm ánh sáng. Nhân lúc tôi đang đọc cuốn Lược sử thời gian (A Brief History of Time) của Stephen Hawking, dưới đây là một số nhận xét và tính toán của tôi. Làm thế nào NASA tìm thấy Kepler-452b? Câu trả lời đơn giản là nhìn lên trời.

Văn hoá tip khi đi ăn ở Mỹ

Ở Mỹ thì đi đâu cũng phải tip. Đi ăn tip. Vào khách sạn tip. Trước khi trả phòng cũng tip. Tip dường như đã trở thành văn hoá ở Mỹ. Văn hoá này không hề có ở Việt Nam và Anh (ăn bao nhiêu trả bấy nhiêu, thậm chí còn chả có thuế vì tất cả đã được tính vào giá bán). Trước giờ đi ăn ở đâu tôi cũng tip, nhưng không phải chỗ nào tôi cũng nhận được service giống nhau.

Giới thiệu Virtual Environment trong Python

x-post from kipalog.com Virtual Environments là gì và dùng để làm gì? Virtual Environment dịch nôm na là môi trường ảo :D Cũng giống như máy ảo (Virtual Machine), Virtual Environment thiết lập một môi trường ảo, cho phép bạn nghịch ngợm lung tung với các packages của Python mà không làm ảnh hưởng đến những packages đã được cài đặt sẵn trên Python. Ví dụ bạn muốn thử nghiệm với Django 1.

PayPal, reddit, Youtube, … đã lôi kéo người dùng như thế nào

x-post from kipalog.com PayPal, reddit, Youtube hay bất cứ trang nào sống nhờ nội dung do người dùng tạo ra (user-generated contents), dù có nổi tiếng đến đâu thì đều trải qua giai đoạn khó khăn ban đầu: thu hút người dùng. Có nội dung thì mới có người dùng, nhưng có người dùng thì mới có nội dung. Sẽ không có ai đăng video lên Youtube nếu không có ai xem, nhưng để có người xem thì trước hết phải có nội dung cái đã.

Giới thiệu SSH Tunnel và một số ứng dụng

x-post from kipalog.com Liệu đây có phải là động lực để mình viết nhiều hơn không? Hy vọng thế. SSH, viết tắt của Secure Shell, là một giao thức mã hoá thường được sử dụng để truy nhập vào các máy chủ từ xa (đặc biệt là các máy chủ Linux). Hầu hết các máy chủ Linux đều được cài đặt mặc định một chương trình SSH Server như OpenSSH hay Dropbear, sẵn sàng phục vụ các kết nối tới cổng mặc định 22.

WordPress Permalink Settings on Windows Hosting

My 2 cents: You should not host WordPress (or any script other than ASP, .NET) on Windows hosting. Try Linux. You will not be disappointed. In case you still want to use Windows hosting for your WordPress, here is a piece of code that will save you lots of time trying to figure out how to update Permalink Settings on WordPress. You will probably got this message: You should update your web.

Interview: Đam mê là chìa khóa thành công cho nghề lập trình viên – Phỏng vấn Hoàng Vũ Tuấn Anh

Mấy hôm trước tôi có trả lời phỏng vấn qua email bạn Hồ Sỹ Hùng ở blog Vinacode. Dưới đây là nội dung đầy đủ (bê nguyên từ đây) “…muốn theo đổi ngành CNTT nói riêng và bất kỳ ngành nào nói chung, điều quan trọng nhất vẫn là đam mê. Không có đam mê mà chỉ làm việc vì cơm áo gạo tiền thì không “sướng”, và khi đã không “sướng” thì đến một lúc nào đó sẽ cảm thấy nhàm chán.

Mailbox (from Dropbox) is using Nodemailer to send your emails from Amazon AWS

So I started testing Mailbox on my iPhone and my Mac recently. It has a very elegant interface and a nice Snooze feature (basically you can tell Mailbox to put some messages back to your inbox to process at a later time – this is quite similar to a Chrome extension — Boomerang). The Mac version is beta, but the iPhone version has been around for more than a year, so I don’t think the core functions will change any time soon.

How to use Tor as a socks5 proxy

Yes, you can definitely use Tor as a socks5 proxy. Never heard of it? Tor is a network that uses peer-to-peer connections to allow people securely surfing the web without leaving any trace. Originally developed by U.S. Naval Research Laboratory, now Tor is being used by millions of Internet users. When you start a Tor session, it also comes with a socks5 proxy at port 9150 on your computer. So you can easily use any application that supports socks5 proxy under Tor with a simple configuration.

Increase “a little” privacy by disabling third party cookies

Have you remember searching for something or browsing some products, and the next day Facebook recommends the same or similar type of products? Companies these days try pretty hard to track your every movement. Cookies is one of the main tracking panel. 1+ button, Like button, social button, … in general come with a tracking code that can track your behavior on the current website, and if, by accident (but very likely) you also logged in to Google, Facebook, …, these information will be linked to your Google, Facebook, … accounts.

Update on DigitalOcean’s connectivity issue with 4.2.2.2

This is the followup post of the following report: []1 Seems that DigitalOcean haven’t fixed anything yet. 8 days since my last post. This page https://status.digitalocean.com/ show no information regarding this issue. Other people also reported similar behavior. Come on, do something DigitalOcean! Here is the latest benchmarks from my server to 3 different DNS provider: 4.2.2.2 (Level3), 8.8.8.8 (Google) and 208.67.222.222 (OpenDNS). I issued 10 dig queries for google.com, each of them 10 seconds apart.

New API: Expand URL

Today, the Internet is flooded with shortened URL. All links shared on Twitter are shortened (start with t.co). There is nothing wrong with it. I just don’t feel comfortable clicking a shortened URL without knowing where it will bring me to. How paranoid I am! There are several reason I don’t trust shortened URL: They might contain tracking or referral code. SlickDeals heavily uses it (to make money, of course).

Speedtest for your Linux server

Have you ever wonder how to test network speed (Internet specifically) of your server? Well, with GUI you can use something like speedtest.net, but how about CLI server, where you only have command-line interface? There are indeed several option: 1. Speedtest for CLI: https://pypi.python.org/pypi/speedtest-cli Install: easy_install speedtest-cli Use: speedtest 2. wget You first need to find some “big” files. My favorite is Ubuntu image: http://mirror.anl.gov/pub/ubuntu-iso/DVDs/ubuntu/14.04/release/ubuntu-14.04-server-amd64+mac.iso Use:

DigitalOcean droplets (at least for NYC2 region) are having trouble connecting to 4.2.2.2

I noticed a noticeable degrade in network performance in my droplets. It took forever to open a connection. It happened from last week I guess. Restart server does not help. I though it’s just temporary. However today I noticed that, DigitalOcean by default assign 2 DNS servers for every droplet in NYC2 region: nameserver 4.2.2.2 nameserver 8.8.8.8 Here is the result for ping from my droplet to both servers: tuananh@codepie:~$ ping 8.

Markdown is available for self-hosted WordPress through Jetpack

Jay! I’ve just noticed that. It’s funny when searching for Markdown on WordPress return this article: Write (More) Effortlessly With Markdown Basically, they mentioned that Markdown is only available for WordPress.com blog, by a simple switch in configuration. I am skeptical, so I always try to use “official” version of plugins. Yes, there are many Markdown plugins out there http://wordpress.org/plugins/tags/markdown When I check my Jetpack version, it’s already there! So if you want to write in Markdown style (like Github and StackOverflow), just enable it (why not?

MySQL bug prevents you from connecting to custom port on MySQL server

It took me a great deal of time and effort to figure out this. In MySQL-client you can specify hostname and port to connect to a different MySQL instance on a different machine and/or different port rather than default localhost instance on your machine. For example, I have 2 MySQL instances running on two different machine, and one of them is behind firewall. Therefore, I need to use SSH tunnel to forward requests to port 3306 of the machine behind firewall.

Dropbox-like synchronization for Linux

One of the requirement for load-balancing servers is server file need to be synchronized. Otherwise, part of your visitors can see your new WordPress post but won’t be able to see the attached photos. rsync can’t do the job properly, because any synchronization tool need to look at the previous state of files in order to determine if new files have been added or any file has been changed or deleted.

My perfect setup (hint: CloudFlare, DigitalOcean, StartSSL, nginx, apache and private servers)

My situation is a little bit complicated: I have a powerful server completely under firewall (no inbound connection from outside) I want to run several websites (mostly blogs) I want to support SSL At the beginning, DigitalOcean is the best choice. I will have my own server, host unlimited websites, have full control and DigitalOcean is blazingly fast. I selected the smallest plan with 20G SSD and 512MB RAM.

Replace tab with space in Vim

I’m a fan of spaces. I hate tabs, actually. It does not look good on vim, git, … you name it. Unfortunately lots of Linux config files are still using tab, like apache2 and so on. I’m like, why don’t they switch to space completely. The reason is that, under standard screen (80×24), each tab costs 8. After several indentation, you hardly can see anything or almost every line of config will be break into two lines.

Today I Leaned (the hard way): The difference between dict and list and Python

Lookup time for dict() is O(1) and for list() is O(n) no matter what the number of elements is. Given a list of elements in a file, this piece of code: from itertools import izip lists = map(str.strip, open('dict.txt').readlines()) i = iter(lists) j = range(len(lists)) dicts = dict(izip(i, j)) index = dicts[w] is n time faster than this piece of code: dicts = map(str.strip, open('dict.txt').readlines()) index = dicts.index(w) I learned that the hard way.

CloudFlare + StartSSL is the way to go in mid-October

In my opinion, SSL should be enabled everywhere. HTTP was designed without security in mind. It was 1989, when Tim Berners-Lee first proposed the “WorldWideWeb” project. At that time, the most important thing is to deliver web content to internet users. Things has changed significantly in the last 10 years. Sniffing plain HTTP content is easier than ever. People care more and more about privacy, especially when Non Such Agency use complicated monitoring infrastructure to spy their own citizens.

Simple tool for load-testing HTTP server

Today I came across a very simple tool for load-testing. It’s called AB and come with Apache HTTP Server. The command line arguments are very simple:ab -n 10000 -c 10 http://your_web_site/url.html Where -n is the number of successful requests and -c is the number of concurrence connections. If you want to have more control over the URL you want to test, and much more, I recommend JMeter (also from Apache)

Quick and dirty way to prevent XML-RPC Pingback Attacks

XML-RPC Pingback Attacks are really annoying. You often see lots of POST /xmlrpc.php requests from different IP address from time to time. Sometimes, the number of requests is big enough to crash a server (yes, my server is a tiny angel). But I can’t disable WordPress XML-RPC because I need that for Jetpack to work (post by email, how cool!). Therefore, I figure out a quick and dirty way to prevent this by only allow Jetpack IP address to call XML-RPC.

Clean unused daemon scripts in Linux

Using update-rc.d. This script is very helpful. The advantage of using update-rc.d is that it will take care of removing/adding any required links to /etc/init.d automatically. See the full thread here: http://www.debuntu.org/how-to-managing-services-with-update-rc-d/

Using Bitcoin is not eliminating fees — unless exchanges are no longer required

_Disclaimer: I’m not expert/investor in Bitcoin. I see Bitcoin as a great opportunity and great replacement for traditional money. Want to know more about Bitcoin? Pay this a visit: http://www.reddit.com/r/bitcoin_ Recently more and more people talk about Bitcoin: Very convenient, fast, low fees, etc. Sounds fun, and it’s true, if you only consider Bitcoin transactions alone. By design, it’s very fast, irreversible, secure, completely verifiable and very low fees. However, let’s consider several scenario to see if it’s really true:

How to use Macports version of gcc

OSX Mavericks only support gcc version 4.2.1. Macports, however supports gcc from 4.2 to 4.9. However, when you install gcc through Macports, your new version will not be enabled automatically. Here is a little trick: sudo port select --list gcc Available versions for gcc: mp-gcc44 none (active) The following command will enable your desired version: sudo port select --set gcc mp-gcc44 You will need to do an extra step: Open a new Terminal and type hash -r to register the change with your system.

How to install Oracle Database 12c on RedHat Enterprise Linux 6

IMHO, installing Oracle Database is not straight forward. There are lots of prerequisites packages and configurations that need to be installed and configured before you can actually install Oracle Database. Especially if you have a headless server that does not have any physical display attached to it, because you cannot install Oracle Database on a headless server without a response file (a response file is basically a configuration file that automate the installation process – however in order to create a response file, you will need another machine with display).

How to solve “Too many authentication failures for…” problem

Recently I am having trouble connecting to my home server from my laptop. Every time I connect, it said:Received disconnect from my_ip: 2: Too many authentication failures for my_username The strange thing is, connect from any other machine did not give me this problem. Is there anything wrong with my laptop? Even with multiple failures, my home server should reset login count sometimes. Turn out the problem belongs to my SSH keys.

Extract pages from PDF in Linux

I am not usually have to extract pages from a pdf file, but when I do, I used Adobe(R) Acrobat 7.0 that resides on my old Windows XP machine (believe me, it’s still work at this time). Today one friend asked me to extract a page from his pdf file, and I only have my MAC and Linux workstation with me. Fortunately, I figured out I can just use a single command to do this.

How to install rtorrent and rutorrent

In order for rutorrent to work, rtorrent must be compiled with xmlrpc-c support. Here is the full instruction. First, check to make sure the following libraries are installed on your system. At any step below, if you cannot run ./configure script correctly, you might have to install -dev or -devel packages of these libraries gcc ncurses libsigc++-2.0 libssl xmlrpc-c subversion Download and install xmlrpc-c if your distro does not support it svn co http://xmlrpc-c.

How to connect to NYU-Poly wifi using Nokia E71 (and other Symbian phones)

I’ve been struggling with connecting to Poly-WiFi network using my Nokia E71. This page gives instruction to connect for iPhone, Windows and Mac but not for Symbian. Fortunately, after some finding on Internet and researching Poly network, I can define the correct configuration that enables my E71 to connect to Poly wireless. Here is the configuration detail: Step 1: Go to Menu -> Tools -> Settings -> Connection -> Access points and add new access point with the following information:

16/2/2009 – 29/6/2012 – Kết thúc một chặng đường

Mới đó mà đã hơn 3 năm. 3 năm làm việc là chính, ăn chơi là chủ yếu, trải qua bao sóng gió thăng trầm của lịch sử, chứng kiến sự ra đi và trở lại của không biết bao nhiêu con người. Và rồi ngày ấy cũng đã đến, ngày mà mình chính thức bị xếp vào hàng ngũ “cựu nhân viên”. Ấy là vào cuối năm 2008. Lúc đó mình cũng kinh qua một vài công việc part time nhưng không được nhận lương.

Thử một bài viết có rất nhiều tiếng Việt

Bài viết này lẽ ra đã không được publish. Mục đích của mình chỉ là kiểm tra xem WordPress 3.4 xử lý tiếng Việt trong Permalink như thế nào. Trước 3.4, WordPress xử lý việc này không tốt, cụ thể là với tiêu đề như trên, WordPress sẽ xử lý thành “thử-một-bai-viết-co-rất-nhiều-tiếng-việt”. WordPress 3.4 đã xử lý việc này rất tốt, URL trở thành “thu-mot-bai-viet-co-rat-nhieu-tieng-viet”. Dưới đây là đoạn code được mình viết và đặt trong file wp-includes/formatting.

Kinh nghiệm phỏng vấn VEF

Disclaimer: Bài viết dưới đây dựa trên kinh nghiệm cá nhân khi tham gia chuẩn bị và phỏng vấn VEF. Bài viết có thể có một số điểm tương đồng với bài viết của Thắng (MSE – UCB) và Kiên (CS – Poly) vì chúng tôi có nhiều đoạn giao nhau trên suốt chặng đường. Xem kỹ lại hồ sơ, tức là những thông tin đã điền trong application form và những giấy tờ đã nộp cho VEF hôm OEO.

Một số câu hỏi chuẩn bị phỏng vấn VEF

Dưới đây là khoảng hơn 100 câu hỏi, được tôi, Lê Sỹ Tùng (VEF Fellow 2012), Nguyễn Quang Trung (VEF Fellow 2012), Ngô Xuân Hoàng và Đào Duy Anh chuẩn bị hồi tháng 7 năm ngoái. Nhóm tôi gồm có 6 thành viên chính (thêm Trần Đức Mạnh nữa) trong đó có 3 người được VEF Fellowship 2012 (chính tôi sau đó là người bỏ VEF để apply tự do và cũng sẽ sang NYC vào tháng 8 này).

Tôi đi xem hòa nhạc

Tôi vốn tính nhà quê, chân đất mắt toét, từ ngày chân ướt chân ráo lên Hà Nội đến giờ có biết ca nhạc, nhạc kịch hay hòa nhạc là gì đâu, lại càng không dám mơ một ngày được đặt chân vào Nhà Hát Lớn. Chỉ thỉnh thoảng bỏ tiền ra đi xem phim, thế là cũng văn minh lắm rồi. Thế nên hôm trước, cầm trong tay 2 tấm vé đi xem hòa nhạc mà lấy làm vui sướng lắm.

How to disable comment box from Facebook like widget

It have been a long time since the last time I used Facebook like widget on my blog. At that time, I feel that Facebook scripts take a lot of time to load, hence slowdown my site and affect its performance. Today, I changed my mind and add it back. With just 2 pieces of code (one load all.js at bottom and one load the like button), Facebook like button appears again on my site.

How to find all files of a particular size in a particular directory

Last weekend, I worked on a Linux malware cleaning project. After 30 minutes of finding, I found 2 suspected scripts that are not included in Drupal by default. I soon realized that there are many of them, and I have a very limit access to his website (just normal account SSH access). Fortunately, after doing some research, I found that I can easily find all files of a particular size in his home directory.

Cảm nhận ban đầu về Google Drive

Có thể nói, Google Drive đã thực sự làm mình thất vọng. Ngoài một số ưu điểm như: Dung lượng ban đầu lớn (5GB) Giá cho 25GB tiếp theo rất rẻ (so với Dropbox) Download/upload nhanh thì Google Drive vẫn còn có quá nhiều nhược điểm. Giao diện giống hệt Google Docs, hệt như là Google chỉ việc đổi tên chữ Docs thành Drive. Không có một số tính năng tối thiếu của một chương trình duyệt file, ví dụ như chuyển đến thư mục cha, tính năng copy/move khó truy nhập.

How to generate SSH public key from private key

Normally you will generate and store a pair of SSH public and private key. But do you know you can generate public key from private key with ease? Here is the trick: For OpenSSH key: Open terminal and type: ssh-keygen -y For PuTTY key: Open PuttyGen program and choose Load key. Public key will show up. Have fun.

How to format bytes to kilobytes, megabytes, gigabytes in PHP

This is the best function I found on StackOverflow: function formatBytes($bytes, $precision = 2) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); // Uncomment one of the following alternatives // If 1 kilobytes = 1024 bytes // $bytes /= pow(1024, $pow); // If 1 kilobytes = 1000 bytes // $bytes /= (1 < < (10 * $pow)); return round($bytes, $precision) .

March 29, 2012 – Final Decision

12:30am 29/3/2012: Sent withdrawal email to VEF Team. Vậy là đã (chưa chính thức) không còn là người của VEF nữa rồi. Bao năm phấn đấu và cố gắng, thế mà giờ đành phải nhường lại suất học bổng này cho người khác. Mình vẫn còn rất nhớ hồi tháng 9 năm 2008, mình và Bách rủ nhau đi thi TOEFL ITP ở trường Ngoại Thương để nộp hồ sơ VEF.

February 22, 2012 – Cố lên tí nữa

(bài này định viết từ cách đây 1 tiếng, nhưng bị cuốn đi bởi mấy việc ở công ty, thành ra quên mất) (mất thêm 30 phút nữa) Số là trong khi các bạn có admission ầm ầm (cơ mà nói chung thế thôi, chứ ngành CS thì vẫn thường bặt vô âm tín như vậy), thì mình vẫn cứ phòng không. Nói phòng không thì không đúng lắm, mình đã được một gs ở NYU-Poly offer RA (non-VEF), một gs ở UCSB phỏng vấn và hai gs ở USC và UA xem xét hồ sơ.

How to know exactly which Linux distribution you are using

I myself usually have to connect to a lot of Linux server to troubleshot. As you know, different Linux distribution has different config file location. For example, Apache config file in CentOS server is /etc/httpd/httpd.conf but in Ubuntu/Debian is /etc/apache2/apache2.conf It would be easier for us if we know exactly the distribution name from the beginning. Here are several solutions: 1. From the boot time message dmesg | head -1 You might see something like this:

CSS: How to add width and height attributes to anchor tag

You might face this problem sometimes: You want to add width and height to an anchor instead of giving these attributes to its container. Surprisingly, width and height attribute are not works. For example, consider the following codes: a.ansok { width:86px; height:41px; line-height:41px; background-image: url(../images/layout/button.png); } And here is what you will get (instead of beautiful buttons): So, what is the reason and how to fix it? Well, anchor tags are not block level HTML elements but rather inline elements.

How to install Ant correctly on Ubuntu

When using Ant the first time, you might notice that it return errors ant -version Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar Is it because of wrong jdk version? You probably tried to locate tools.jar and found this: locate tools.jar /usr/lib/jvm/java-6-sun-1.6.0.06/lib/tools.jar Is it the same tools.jar required by ant? How can you point to this file so ant will not return any error? Here is the solution:

How to make Cufon works in IE9

IE, and probably Microsoft, has a lot of surprises for you. As you know, each IE version has its own behavior. And don’t surprise if IE9 does not render Cufón at all Meaning that every beautiful things you see in Firefox, Chrome, … will not even show up in IE9. Nothing. You will only see a blank space. Then, how to fix it? First, you need to download the latest version of Cufón.

PHP: eval() without output to screen

Sometimes, we need to eval() some lines of code and grab the result without output to screen. As you know, eval() has only one parameter, so we have to use output buffer for that purpose. The following code can achieve that. Pretty clean and understandable: ob_start(); eval('echo "Hello world!";'); $str = ob_get_contents(); ob_end_clean(); $str will hold the output returned by eval function.

Format post date in WordPress

We all know that $post->post_date will display post date in the following format: 2011-08-19 17:23:25. The problem is that, if we want to display post date in different format, what should we do? Fortunately, WordPress has a very useful function mysql2date. Suppose you want to display only Month and Year of the post, you should be able to do that using this snippet: < ?php echo mysql2date('F Y', $post-post_date) ? The first parameter of this function can be referred in date function of php.

How to count number of search results returned by WordPress

Suppose you want to create a custom search result for your theme. Apparently you will create a php script named search.php. One problem is that, you want to display total number of search results returned. Here is the solution for that. Searching for: < ?php echo get_search_query(); ? < ?php $allsearch = &new WP_Query("s=" . get_search_query() . "&showposts=-1"); $count = $allsearch-post_count; ? < ?=$count? results found: Happy coding!

Host … is not allowed to connect to this MySQL server

Suppose you’ve installed LAMP (Linux, Apache, MySQL, PHP) in your server. Everything is working fine. One day, there was a problem on your server. You don’t want to use the command line mode of MySQL because it is very difficult to debug. So, you grab a tool, for example SQLyog to connect to that server. Surprisingly, you cannot connect and the sever give you a weird message: ERROR 2003: Can't connect to MySQL server on 'host_name' (111)

Why are private fields not private to the instance?

In C# it’s perfectly legitimate to access private fields of other instances of the same type. C# specification also state that access to private fields is on a type, not an instance. Is there any reason for that? public class Foo { private bool aBool; public void DoBar(Foo anotherFoo) { if(anotherFoo.aBool) ... } } One reason for this is that, access modifiers work at compile time. As such, determining whether or not a given object is also the current object isn’t easy to do.

List contents of a directory by date in PHP

Sometimes, you need to list all contents of a directory, for example, to display all images in a specified directory. Unfortunately, PHP native functions to handle files and directories have a very limited capabilities. For example readdir, opendir and much more only takes 1 parameter. You might wonder how to list contents of a directory by date. Here is one solution for that problem: function listdir_by_date($path){ $dir = opendir($path); $list = array(); while($file = readdir($dir)){ if ($file !

How to solve dependency problem when install Squid on CentOS 5.5

If your server is running CentOS 5.5 and you are trying to install Squid, you might got this error: Error: Missing Dependency: perl(URI::URL) is needed by package 7:squid-2.6.STABLE21-6.el5.x86_64 (base) The solution for this problem is pretty simple: Download and install perl-URI from CentOS cd /usr/src wget ftp://ftp.pbone.net/mirror/ftp.centos.org/5.5/os/x86_64/CentOS/perl-URI-1.35-3.noarch.rpm rpm -ivh perl-URI-1.35-3.noarch.rpm Now you can use yum to install Squid as usual yum install squid Pretty simple, huh?

Remove one or more values from array in PHP

The solution is quite simple: Using built-in function array_diff of PHP: $dest_array = array_diff($src_array, array("value_to_remove_1", "value_remove_2")); Of course you can use this method to remove just one value from array: $dest_array = array_diff($src_array, array("value_to_remove")); One problem of this method is that, there are some holes in $dest_array after apply this method. There are some ways of solving that problem: Remove all key strings from the array and replace them with numbers, use array_values Preserve the key names (strings), or reindex the array if all keys are numerical, use array_merge

Install Django on Bluehost shared hosting

In this series, I will tell you how to install several development tools on Bluehost shared hosting. Why need to purchase a VPS or dedicated hosting if your site is small, and you can install almost everything on Bluehost shared hosting. Take a look at Install git on Bluehost shared hosting to see how I managed to install git on Bluehost. Pretty easy. Bluehost support 2 versions of Python: 2.4 (default) and 2.

Install git on Bluehost shared hosting

For developer like me, git and svn or any version control system is a must. And Bluehost does not support git out-of-the-box nor tell you how to install it. But if you have SSH access (if not, request — pretty easy), you can install git with some simple steps. You have to specify where to install git. It should be inside your home directory because outside this directory, everything else is read-only.

Things I have learned in programming (June 26, 2010)

Working in a startup company is an oportunity. You will have chances to get familiar with many programming languages. For me, they are PHP, JS, Python, XBL (Firefox Add-on), C#, C++, Bash, Windows Commandline (and of course, HTML and CSS) XBL 1.0 is a Mozilla-specific technology, and not a W3C standard. However, at least two standards are being worked on: sXBL and XBL 2.0. In my opinion, XBL is more powerful than XHTML.

Things I have learned in C# (June 23, 2010)

Yesterday, I faced lots of problem in C#. Some were new, but some have already solved before but I don’t remember. I think I should write them down, in case I miss it again. 1. Execute a Command in C# CodeProject described two ways to run a command, synchronously and asynchronously 2. Build a .NET Solution or Project from the Command Line This solution comes from C# Corner. devenv can run in command line mode.