splitting and joining huge files

Today I wanted to sftp a 10Gb file over the wire. Knowing that the transfer would fail in the middle of it, I decided to split this file into small pieces beforehand. Below I think is the easiest way on osx. // to split my huge file into 100mb files, having the prefix "bak_" split -b 100m my_huge_file.ext bak_ // to re-construct my huge file cat `ls bak_*` > my_huge_file2.ext After running the split command, you will see some files named bak_aa, bak_ab, etc in your directory. These are the chucks of your original huge file. So just transfer these small bak_* files over the wire. ...

November 3, 2012 · 1 min · birdchan

PHP explode

Say you store a csv formatted string somewhere to represent an array. For example, Johnny has items “apple|orange|banana”. Then in your code, you may parse out the items as follows: $items = "apple|orange|banana"; // retrieve it from somewhere $my_arr = explode("|", $items); if (count($my_arr) > 0){ print "Johnny has something."; }else{ print "Johnny has nothing."; } It works fine as it seems. Well, actually, you will never see the “Johnny has nothing” print out. Surprisingly, even if $items is an empty string, explode will still return an array with one element. That array is: ...

November 1, 2012 · 1 min · birdchan

Do what you love and do it often

October 29, 2012 · 0 min · birdchan

A Toy Train in Space

[youtube &w=640&h=360] Makes me want to try as well… ;) http://news.yahoo.com/blogs/sideshow/father-son-launch-toy-train-space-video-222733570.html

October 24, 2012 · 1 min · birdchan

Formatting mysql datetime with php

Very useful, so posting here. Read the php date function page for more details. $mysql_datetime = date("Y-m-d H:i:s"); Ref: http://stackoverflow.com/questions/136782/format-mysql-datetime-with-php

October 23, 2012 · 1 min · birdchan

Caching on wordpress

A while ago when I tried to stress-test my site on Load Impact, my web server actually couldn’t handle the traffic and hung in the middle of the test… Recently I installed this wordpress plugin called Quick Cache (Speed Without Compromise) and I noticed a huge difference in page response time. Installation was a piece of cake. Then I ran the stress test again from Load Impact. The result is very satisfying. The green line is the number of active client. The blue line is the user load time. From the chart, it shows that the average load time is constant even when the # of active clients increases. Amazing! ...

October 21, 2012 · 1 min · birdchan

DNS flush

Sometimes you may need to do a DNS flush, say after a mysterious DNS network issue. Here are the commands. Mountain Lion / Lion sudo killall -HUP mDNSResponder Leopard sudo dscacheutil -flushcache Tiger lookupd -flushcache Windows ipconfig /flushdns Run a nslookup or ping to check if you are indeed getting the correct IP(s) from the DNS server(s).

October 16, 2012 · 1 min · birdchan

OSX Mail too slow?

I notice the Mail application on my Mountain Lion has been running slower and slower. Lately, it’s so slow that the spinning wheel comes out and stays for a while from time to time. It turns out there is a way to speed up Mail. It’s to rebuild the email database. Just go to the Mail menu and click Mailbox, then click Rebuild. Then I suggest you go take a walk. There is really no spinning wheel of any sort to notify you what’s going on, in fact you may not even notice if anything is happening in the background. But from my experience, after you come back, Ctrl-Q your Mail application. Then open it up again, Mail will start indexing your emails. After a while depending on your mailbox size, your mailbox will be a lot faster than before. ...

October 13, 2012 · 1 min · birdchan

Refresh qtip content

qtip2 is very handy to show/hide additional information on websites. The qtip content is by default cached to minimize unnecessary fetching. However though, sometimes it’s desirable to fetch for new content every time the tooltip comes up. In that case, use the once : false attribute to force re-fetching of new content. $('#my_dom_element').qtip({ content: { text: 'loading...', ajax: { url: 'my_content.php', once: false // need to re-fetch every time }, title: { text: 'My title', button: true } }, position: { at: 'left center', // Position the tooltip above the link my: 'right bottom', viewport: $(window), // Keep the tooltip on-screen at all times effect: false // Disable positioning animation }, show: { event: 'mouseenter', solo: true // Only show one tooltip at a time }, hide: 'unfocus', style: { classes: 'ui-tooltip-wiki ui-tooltip-light ui-tooltip-shadow', width: '800px' } });

October 9, 2012 · 1 min · birdchan

ATV焦點2012-09-03

[youtube &w=640&h=360] 是非顛倒,可恥可恥

October 8, 2012 · 1 min · birdchan