Saturday, August 01, 2009

Farewell, Cory

Cannon shots are being fired every 30 minutes at the military base near our house. It surprises the shit out of me, so I wrote a cronjob to warn me of incoming shots:
0,30  *   *   *   *   echo "Incoming cannon shots in 30 minutes." | say -v Vicki
29,59 * * * * echo "Incoming cannon shots in 1 minute." | say -v Vicki

I didn't know Mac OS X speech synthesis feature was scriptable!

Tuesday, June 30, 2009

Agavi Validation

I'm trying to learn how Agavi's validation system works.

I wrote a writeup on my wiki.

Saturday, June 27, 2009

Google Moderator part 2

before sending a new page request, the server checks the differences on what the client already has, and what its going to sent. the difference is then compressed and sent, browser on the client patches it. this should provide amazing improvement.


What kind of files? Generating a diff from file A and B, where A and B are totally unrelated files, results in a file which is more or less the same size as B. Therefore, this won't provide "amazing improvement".

Browsers already support caching and HTTP compression.

My idea is to make a giant web where the internet connection is splitted between the people connected so there is no connection wasted, think for example, when somebody with 10 mb/s turns off the pc nobody can use that speed, maybe you can make it :)


QoS.

Governments should aim to provide affordable broadband access for all citizens, in the same way they provide access to affordable water, electricity or shelter.


Government-run ISP? No thanks.

The government needs to subsidize the various brodband access methods out there. Things like Brodband over Power lines, and low orbit satellites. We've spent 7.4 trillion, one would think there is some money in there to fund this stuff.


Government subsidy? Do you know where that money comes from? From taxes, of course. Are you suggesting that people who don't use the Internet will subsidize people who use 1TB of bandwidth per month? Good thinking!

2 ways to make the web faster, 1st one is stopping illegal contents, spams & peer2peer streams, to access & saturate large % of ISPs bandwidth; the 2nd one is replacing the customer's outdated PSTN cables by optic fiber, but how will pay THE BILL ?

Use bandwidth effectively by removing the limits and allocating it to who use them the most,...instead of giving high bandwidth for a person who uses internet just to check an email, give it to someone who runs a webserver...


You want to censor the Internet? Die, communist, die!





Friday, June 26, 2009

Let's make the web faster: Google moderator

Okay, I'm sufficiently annoyed with the ideas posted in Google moderator. Most of the ideas posted there are not new, and they can be implemented with existing technology. The sad thing is, people vote them up.

most websites are templated on the serverside, and for most websites every page you view means about 20% of data transfer is the template. the template should only load once, and should be done in browsers.


You mean like XSL Transformations, which is already implemented in several Web browsers?

P2P browser: Standard browsing is exclusively client/server. Imagine instead that every browser is a P2P app and reports webpage data it downloads to "tracking servers" so when someone else wants the same page they get it from several peers instead


You mean like The Coral Content Distribution Network?

Extend HTML mark-up with new elements. The code will be more complicated because of more elements, but much shorter. Same with CSS - extend number of properties to resolve different tasks by one style property. Reduce size of properties names for CSS


Extend HTML? Oh, so you mean like XHTML, or the Extensible Hypertext Markup Language?

Apache has modules like mod_perl, mod_php and other that allow you to extend the functionality of the browser. While Firefox 'plugins' do that for the frontend, why not make modules for the 'backend' of the browser that enable you to send PHP or Perl


Send what?

Come up with rules which can't be explained by different ways. Like padding in IE and FF - now to make page with same look in all popular browsers you should add more code and CSS which increase size of page and take more time...


You mean like XHTML Strict?

Developers need to comeup with a way to use the already existing information through browoser. Say if it is the same IP packets receiving from the past try to use it and construct the patterns. Avoid duplicate bits to receive. This helps in bandwidth


You mean like using caching settings in the HTTP header?

Many headers that are being sent as part of every HTTP req. and resp, though all HTTP headers are optional. Web servers have to rethink on file naming and their url references. Smaller data to be transported means faster transport.


What kind of rethinking? What kind of URL references? What kind of naming?

And save what, 8 bytes?

Why don't we have an alternative to HTML? I mean open source, anyone can commit changes to the source, and a group oversees which changes are actually put in place. HTML5 will not be released till 2022, and that's when you realize it's ridiculous.


What's ridiculous is that you think HTML is a program.

w3c should regulate the release of browsers. if a browser doesn't pass all the tests for a standard, it should be allowed to call itself a "browser" . because of browsers not following standards, we forcefully hv to implant hacks, and make web slower


Are you a communist?



Wednesday, June 03, 2009

Moo

simoncpu-dev:~# apt-get moo
(__)
(oo)
/------\/
/ | ||
* /\---/\
~~ ~~
...."Have you mooed today?"...
simoncpu-dev:~# aptitude moo
There are no Easter Eggs in this program.
simoncpu-dev:~# aptitude -v moo
There really are no Easter Eggs in this program.
simoncpu-dev:~# aptitude -vv moo
Didn't I already tell you that there are no Easter Eggs in this program?
simoncpu-dev:~# aptitude -vvv moo
Stop it!
simoncpu-dev:~# aptitude -vvvv moo
Okay, okay, if I give you an Easter Egg, will you go away?
simoncpu-dev:~# aptitude -vvvvv moo
All right, you win.

/----\
-------/ \
/ \
/ |
-----------------/ --------\
----------------------------------------------
simoncpu-dev:~# aptitude -vvvvvv moo
What is it? It's an elephant being eaten by a snake, of course.

Tuesday, June 02, 2009

HOWTO Access a VMWare console from Mac OS X or Linux

Problem

There are no VMWare Server clients for Linux and Mac OS X. VMWare provides a Web UI for its server, but it requires a plug-in that doesn't work* on non-Windows platforms.

Solution
  1. SSH into the VMWare Server.
  2. Navigate to the VM folder, and edit the *.vmx file.
  3. Enable VNC by appending the following settings:
    remotedisplay.vnc.enabled = "TRUE"
    remotedisplay.vnc.port = "5900"
    remotedisplay.vnc.password = "foobar"
  4. Start/restart your VM.
  5. Connect to your VM using a VNC client. I'm currently using Chicken of the VNC. You might want to google for a client that suits you.
If you need to connect to multiple VMs, simply use a different port (5900 for display :0, 5901 for diplay :1, etc).

I haven't tried this with VMWare ESX Server. I'll try this in the office tomorrow.

* It somewhat works in Linux.

Thursday, May 28, 2009

HOWTO Import VMWare Fusion disk images to VirtualBox


Here are the steps on importing VMWare Fusion disk images to VirtualBox.

First, create a hard link from your VMWare package.

simoncpu@soulfury:~/Documents/Virtual Machines$ ln -h "Debian Linux.vmwarevm/Debian Linux.vmdk"
You can move or copy it anywhere you want. What's important is that it's accessible outside the original directory because Mac OS X doesn't treat the package as a navigable directory.

Next, create a new VirtualBox VM. In the "Create New Virtual Machine" wizard, select "Use existing hard disk" and open the Virtual Media Manager. Click "Add", and navigate to the hard link that you've created earlier.

Click "Finish" to create your VM. In theory (i.e., I haven't tested this) the OS will now boot at this point as long as you've used an IDE controller from VMWare. If not, then proceed as follows:

Change your VM's settings and go to the Storage tab. Next, check the "Enable Additional Controller" checkbox and select any SCSI controller from the drop down box. In the Attachments section, change your hard disk's slot from IDE Primary Master to SCSI Port 0.

Click OK, and start your VM.

Thursday, April 30, 2009

Process Management in PHP

My PHP script downloads a series of binary patches and places them into a directory for further processing. It also creates lock files to prevent two or more instances of my script from being run.

The Problem

When the script receives a SIGINT (Ctrl+C) or SIGTERM signal from the OS, my script is prevented from cleaning up the temporary files, which usually occupies hundreds of MB of space. The lock files also become stale, so my script prevents itself from being run until the next reboot, when the /tmp directory is cleaned up.

The Solution

The solution is to catch the signals so that my script is given one last chance to perform cleanup:
function sig_handler($signo)
{
switch ($signo) {
case SIGTERM:
case SIGQUIT:
case SIGABRT:
case SIGINT:
echo "==> Software Update has been aborted.\n";
echo "==> Performing cleanup...\n";
cleanup();
exit();

break;
default:
// Unknown signal. Do something here...
exit();
}

}

pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGQUIT, "sig_handler");
pcntl_signal(SIGABRT, "sig_handler");
pcntl_signal(SIGINT, "sig_handler");

Wednesday, April 29, 2009

tail -F in PHP

I'm currently writing a PHP script that pushes live log data to the front-end UI. I'm using a streaming Comet model such that my back-end would update the front-end's screen every time the log file is updated.

Unix has a nifty utility called 'tail' that can continuously monitor a file for updates and display them to standard output (which is the usually the monitor). By capturing tail's output via popen(), I was able to make a log file viewer with just a few lines:

exec("/usr/bin/killall tail");
// execute myapp in the background and redirect all of its output to logfile
exec("/usr/local/bin/myapp > /var/log/mylogfile.log 2>&1 &");

$handle = popen("/usr/bin/tail -F /var/log/mylogfile.log 2>&1", 'r');
while(1) {
$buffer = fgets($handle);

if (trim($buffer) == '-- ok') { // this string signifies end of execution
pclose($handle);
exec("/usr/bin/killall tail");
exit();
} else {
echo trim($buffer);
// if you're using Comet, push output to the stream here
}

ob_flush();
flush();
}
Very cool...

Wednesday, January 21, 2009

HOWTO Revert your Git repo to a certain commit

Get the SHA1 hash of the commit that you wish to revert to.

% git log

...

commit 9ce5e10ac4fe43e9b580344454dd27172b6c4456
Author: Simon Cornelius P. Umacob
Date: Tue Jan 20 16:30:42 2009 +0800

show/hide icmp6box

commit f193cf92b2c925a2f3f71a713d766efd1e4d81e0
Author: Simon Cornelius P. Umacob
Date: Tue Jan 20 15:52:39 2009 +0800

Merge IPv6 changes

commit 1f9f2a95b7b42cf33e730535092e56e214fdb848
Author: Simon Cornelius P. Umacob
Date: Tue Jan 20 14:55:07 2009 +0800

Merge IPv6 changes

commit ce996bd3014b05fea5eaffd7c738c5c549fd7677
Author: Simon Cornelius P. Umacob
Date: Tue Jan 20 14:30:27 2009 +0800

add IPv6.inc and NetUtils.js

...

% git reset --hard ce996bd3014b05fea5eaffd7c738c5c549fd7677

HEAD now points to ce996bd3...

To go back to the "original" HEAD, find its SHA1 hash and reset your current HEAD to that state.

% git reflog
simoncpu@pfsense:/home/pfsense/simoncpu-IPv6> git reflog
74fb85b... HEAD@{0}: pull git@rcs.pfsense.org:pfsense/mainline.git: Fast forward
9ce5e10... HEAD@{1}: commit: show/hide icmp6box
f193cf9... HEAD@{2}: commit: Merge IPv6 changes
1f9f2a9... HEAD@{3}: commit: Merge IPv6 changes
ce996bd... HEAD@{4}: commit: add IPv6.inc and NetUtils.js
cfc4dab... HEAD@{5}: clone: from http://gitweb.pfsense.org/pfsense/simoncpu-IPv6.git

% git reset --hard 74fb85b

Note that you need not use the full SHA1 string to refer to an object.
The first few characters is enough.

Friday, January 16, 2009

pfSense IPv6

I'm currently merging our IPv6 changes to pfSense by hand so that I can commit our changes upstream once their migration from CVS to git is complete.

"With a thousand eyes, all bugs are shallow", they say. Sharing this code to the world will most likely uncover many bugs and make our code more stable. I just hope that with a thousand eyes, I won't receive a thousand flak from users in case I break something.

I'll probably break something. :)

UPDATE: As of January 16, 2011, development has been stopped. If you wish to continue development, please contact me (simoncpu at gmail.com) or post a bounty. Thanks! :)


(whoah, I realized that this post was made exactly 2 years ago lol)

Friday, January 09, 2009

HOWTO let lighttpd listen to both IPv4 and IPv6 requests on *BSD

Problem
When enabling IPv6 using server.use-ipv6 = "enable", lighttpd no longer listens to IPv4 requests.

Solution
Set a sysctl knob so that it will accept both IPv4 and IPv6 requests:
root@soulfury:~# sysctl net.inet6.ip6.v6only=0

Tuesday, November 25, 2008

pf IPv4 and IPv6 shortcut

There's a shortcut for creating a pf rule that applies to both IPv4 and IPv6. E.g.:

pass in quick on em0 from { 192.168.86.0/24, 2001:418:c0de:babe::/64 } to any keep state label "experimentation"

Results in:

root@soulfury:~# pfctl -sr | grep experimentation
pass in quick on em0 inet from 192.168.86.0/24 to any flags S/SA keep state label "experimentation"
pass in quick on em0 inet6 from 2001:418:c0de:babe::/64 to any flags S/SA keep state label "experimentation"

Monday, November 24, 2008

Hello world from links

I forgot to bring my MacBook, so I'm now surfing the Net in a text-only browser inside a server. I'm surprised that Blogger works. Very cool.

Saturday, November 22, 2008

Hello world from Acer 4330 and Windows Vista

Hello world! WLAN and LAN works fine.

Acer 4330 Driver Installation

I'm continuing the setup for my Acer 4330 laptop. I gave up installing Windows XP because I don't have the time to hunt down the correct drivers. I've installed Windows Vista instead.

I'm annoyed with Vista's UI. Fortunately, I won't have to use this because I'll give this to my parents. Sorry mom and dad, I really don't have time to install XP. This is the best I can do.

The DVD provided with the laptop contains multiple drivers. I think Acer doesn't use a standard hardware for all of its laptops. I think they just choose the cheapest hardware available at the time of production.

Anyway, here are the drivers that worked for me:
Chipset - Intel Chipset
VGA - Intel VGA driver
Audio - Realtek (No need to install; it works after installing Vista. Install this if you want the volume buttons to work.)
Modem - Foxconn, probably, but I didn't install it
LAN - Realtek
TouchPad - ALPS Touchpad
Card Reader - I don't know; there was no need to install it.
Camera - There are 3 drivers (Suyin, Bison, and Chicony), but I didn't bother installing any of them. Please leave a comment if you know the correct one.
WLAN - Atheros
BlueTooth - the only driver, Foxconn, doesn't seem to work. I'm not sure if there's really a built-in Bluetooth in this laptop. There's a Bluetooth button, but this may have been reserved for other models.

Friday, November 14, 2008

HOWTO Turn off DHCP Servers in VMware Linux

To turn off VMware's DHCP server in host-only network, simply find the appropriate DHCP process, and kill it:

root@soulfury:~# ps auxww | grep dhcp
root 5060 0.0 0.0 1892 252 ? Ss Nov10 0:00 /usr/bin/vmnet-dhcpd -cf /etc/vmware/vmnet8/dhcpd/dhcpd.conf -lf /etc/vmware/vmnet8/dhcpd/dhcpd.leases -pf /var/run/vmnet-dhcpd-vmnet8.pid vmnet8
root 5061 0.0 0.0 1888 520 ? Ss Nov10 0:00 /usr/bin/vmnet-dhcpd -cf /etc/vmware/vmnet1/dhcpd/dhcpd.conf -lf /etc/vmware/vmnet1/dhcpd/dhcpd.leases -pf /var/run/vmnet-dhcpd-vmnet1.pid vmnet1
root 21281 0.0 0.0 2796 748 pts/0 R+ 15:31 0:00 grep dhcp
root@soulfury:~# kill 5061

Thursday, November 13, 2008

FreeBSD Problem: Can't see files/dirty state at each boot.

Weird problem. The filesystem is in an unclean state at each boot, even though I have ran fsck before booting the system. Initially, our problem is that our app can't "see" certain files at first read, although subsequent attempts on reading them are OK. Later, we discovered that the filesystem is dirty at each boot. The problem is similar to this issue in FreeBSD-CURRENT. We're using FreeBSD 7.0-RELEASE though, so I'm not sure if we have the same problem. I need to track this down.

Tuesday, November 04, 2008

PHP doesn't support dot characters in form names

I've written a PHP proxy script that communicates with an underlying application. I encountered a problem where the script is unable to proxy data that contains dot characters in the form name.

To illustrate:
<?php
var_dump($_POST);
?>
<form action="test.php" method="post">
<input name="this.is.a/variable" type="text" />
<input type="submit" />
</form>
Output:
array(1) {
["this_is_a/variable"]=>
string(0) ""
}
Notice the array key in the var_dump(); dots are converted into underscore.

Solution

I accessed the raw input stream directly instead of using $_POST:
<?php
$data = file_get_contents("php://input");
$response = proxy_blah_blah($data);
?>

Tuesday, October 28, 2008

HOWTO Install Windows XP on Acer 4330

(Image courtesy of Raymond.CC)

I bought an Acer Aspire 4330 a few days ago, but I couldn't install Windows XP. I think it's designed for Vista, but I don't want to use it because it's unusable. Windows XP Setup coredumped after a minutes, and I thought I had to slipstream the installation CD to solve this. Fortunately, a friend told me that all I had to do was to change my SATA mode from AHCI to IDE. The setup then went smoothly.

Installing the drivers is a PITA. The drivers in the provided DVD doesn't work because they're for Vista. I had to download the files from their FTP site.

Unfortunately, they provide multiple drivers for the same device. Do I need to use the driver for Atheros? Or Broadcom? Or Intel? Blah.

I'll continue installing the drivers tomorrow. I still have to finish this router/load balancer that I'm making. Hopefully, our connection would become twice as fast after we combine Bayantel and Globe connections. More on this later.