> Adam.prototype
Human
> Adam.timestamp
1279148700
> Adam.length
50.17
> Adam.weight
3.4
> Adam.health
Checking.... Good
> Adam.mother.health
Checking... Good
> Adam.father.status
"Happy"
Friday, July 16, 2010
var Adam = new Child(Ariya);
Friday, July 09, 2010
faster quaternion multiplication
Sweet memories, it was fun to derive it.
Faster here however must be taken with a grain of salt as the new code is not always guaranteed to be better pipelined.
And of course, it's trivial to beat this generic C code with architecture-specific hand-rolled assembly.
git show cbc22908 commit cbc229081a9df67a577b4bea61ad6aac52d470cb Author: Ariya HidayatDate: Tue Jun 30 11:18:03 2009 +0200 Faster quaternion multiplications. Use the known factorization trick to speed-up quaternion multiplication. Now we need only 9 floating-point multiplications, instead of 16 (but at the cost of extra additions and subtractions). Callgrind shows that the function now takes 299 instructions instead of 318 instructions, which is not a big win. However I assume the speed-up has a better effect for mobile CPU, where multiplications are more expensive. Reviewed-by: Rhys Weatherley diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h index 55c871d..9a1b590 100644 --- a/src/gui/math3d/qquaternion.h +++ b/src/gui/math3d/qquaternion.h @@ -198,24 +198,17 @@ inline QQuaternion &QQuaternion::operator*=(qreal factor) inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2) { - // Algorithm from: - // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q53 - float x = q1.wp * q2.xp + - q1.xp * q2.wp + - q1.yp * q2.zp - - q1.zp * q2.yp; - float y = q1.wp * q2.yp + - q1.yp * q2.wp + - q1.zp * q2.xp - - q1.xp * q2.zp; - float z = q1.wp * q2.zp + - q1.zp * q2.wp + - q1.xp * q2.yp - - q1.yp * q2.xp; - float w = q1.wp * q2.wp - - q1.xp * q2.xp - - q1.yp * q2.yp - - q1.zp * q2.zp; + float ww = (q1.zp + q1.xp) * (q2.xp + q2.yp); + float yy = (q1.wp - q1.yp) * (q2.wp + q2.zp); + float zz = (q1.wp + q1.yp) * (q2.wp - q2.zp); + float xx = ww + yy + zz; + float qq = 0.5 * (xx + (q1.zp - q1.xp) * (q2.xp - q2.yp)); + + float w = qq - ww + (q1.zp - q1.yp) * (q2.yp - q2.zp); + float x = qq - xx + (q1.xp + q1.wp) * (q2.xp + q2.wp); + float y = qq - yy + (q1.wp - q1.xp) * (q2.yp + q2.zp); + float z = qq - zz + (q1.zp + q1.yp) * (q2.wp - q2.xp); + return QQuaternion(w, x, y, z, 1); }
Monday, June 21, 2010
proxy server with filtering feature
Beside exploring San Diego, I had done some coding intermittently only. My apology if I do not update X2 with fresh new examples often enough.
Having said that, here is one network-related example: a minor tweak to the previous example of Qt-based proxy server. Basically it adds a minimalistic URL filtering support, in the form of blacklisting certain URLs which start with some predefined strings. The code is available in the usual place, X2 repository, under the directory network/filterproxy.
While major browsers support some variants of content blocking, be it via an extension like AdBlock or as a feature built-in into the browser itself, this new filterproxy should work with any browser that supports proxy. Alas, I did not bother to implement an AdBlock-compatible rule system because it would complicate the code. Again, consider this is a proof of concept only. A challenging exercise would be to fully support the most known subscription filters.
It is unheard that content filtering can dramatically improve your browsing experience. Because it cuts the bandwidth usage, it does translate to lower cost for those who are not lucky enough to get unlimited data plan. But most importantly, throwing garbage out of the web pages definitely speeds up the page loading. For this filterproxy example, I did a very unscientific benchmark and test it with Detik.com news site (now you get the answer why the included blacklist.txt contains only some basic advertisement-laden sites). The screenshots below (click to enlarge) show the unfiltered version (left) and the filtered version (right). Notice also the whopping 40% of bandwith saving!
My promise was to post two variations from that simple proxy example. This counts as one of them, and when the time allows me to clean-up to the other, you'll know it. Stay tuned and happy proxying!
spring-to-summer: photo blog
Since I've not been blogging for a while, let me do a post on some pictures (plus the stories) instead.
On a weekend, Balboa Park is a very nice attraction. Rather than explaining it in details, I suggest to just drop the park a visit. Beside a lot of different types of museum, there is also this Japanese Friendship Garden. A small cafe there, the Tea Pavillion, is a very nice place to relax and enjoy the surrounding. They serve sencha and other types of tea. Hungry? Get a rice bowl:
If you are more a beach person instead, then there is a plenty of choices, for example Silver Strand Beach. It is rather small, but it is always a nice spot to enjoy the sunset.
When I was at Google IO, I took some pictures of the large overhang banners because I wanted to test the 8 megapixel camera of HTC EVO 4G that Google gave away (see more in the complete set):
Getting a fantastic gift for the Father's day? Thinking of something for the next Mother's Day? What about a beautiful pendant (get one from LuShae Jewelry) like what my other better half elegantly captured below?
Tuesday, May 18, 2010
google io 2010
In few hours, I am scheduled to fly to San Francisco, bracing for the impact of Google I/O 2010!
Quake and WebGL
While I'm there, let me just quickly blog about it. Using the developer version of Chromium on OpenSUSE, I just run it with the following arguments:
/usr/bin/chromium --enable-webgl --in-process-webgl
and then I have WebGL at my fingertip. You can test it with some O3D samples (the pool one is pretty cool).
In fact, just go ahead and play Quake II at http://playwebgl.com/games/quake-2-webgl/.
I got bad FPS because I own a cheap laptop (8 FPS is more than what I expect from a $330 box). Obviously you can get 25 FPS or more on a much better machine!
Saturday, May 15, 2010
QNetworkAccessManager, tracenet, Speed Tracer
Just like Rich's trick with QNetworkAccessManager, I have done something similar which I call tracenet (around 150 lines of code). Though I have committed this example to X2 some time ago, only now I have the chance to blog about it.
The idea is to subclass QNetworkAccessManager and reimplement its createRequest method so that we can keep track all the network responses and replies. This is useful for your network-based application, or even for e.g. QtWebKit. As a matter of fact, the tracenet example captures the network traffic as you load a URL into a web page.
Now, the next step is how to visualize the result. While it's certainly possible to craft a Qt-based fancy GUI for this (maybe using Qt Quick?), let's think outside the box. Unless you live in a cave, I am sure you are aware that there is this nice tool called Speed Tracer, part of GWT, an extension for Google Chrome or Chromium. For this purpose, we won't use the live profiling feature of Speed Tracer, but rather its ability to visualize network requests and replies (with nice timeline and so on). All we have to do is to carefully spit some JSON-formatted data that match the Speed Tracer data dump format. And that is exactly what tracenet does!
The screenshot below gives an exemplary result from running tracenet on my Nokia N900 when it accesses New York Times front website, a notoriously complicated web page. All I did was to execute "tracenet > nytimes.htm", transfer back the HTML file to the laptop and then open it with Chromium on OpenSUSE, click on "Network (resources)" line, and voila! You can click on each entry to get detailed timing info, use zoom in/out, and many other features of Speed Tracer. Refer to some tutorials if you are new to Speed Tracer.
If you want some follow-up and challenging exercise, try to split Speed Tracer code so that the pure GWT-part can run on any browser. Then you can just package it with QtWebKit and use it to show the outcome of all your network sniffing. Have fun!
Sunday, May 09, 2010
vittoria: tiger in color
Continuing from the saga I started some time ago, at least now I got to the point where it's rendered anti-aliased in full color:
Stay tuned, I'd clean-up and release the code soon-ish.
Thursday, May 06, 2010
vector graphics, tiger in wireframe
At the risk of starting another yet-will-be-unmaintained project, sometime ago I decided to continue learning about graphics stuff in my spare time. I will not announce it of course until its code is better for public consumption. However, I really can't contain my excitement when it reaches an important milestone:
This sounds like childish, but as a graphics n00b, the above screenshot means a lot to me.
Stay tuned!
Saturday, April 10, 2010
cupertino
Tomorrow, we (a bunch of Qualcomm folks working on WebKit) will go up north. We'll be at Apple HQ in Cupertino for the WebKit contributors meeting. I look forward to meeting all the great WebKit hackers (again) face-to-face!
Monday, April 05, 2010
simple http proxy server in 100 lines
I guess a simple proxy server should have been an example in Qt Network module. What I mean of course a real proxy server based on Qt, not about using a proxy server via QNetworkProxy class. After all, there are other more complex examples like the torrent client and Google suggest (yeah, blame me for the latter). As a matter of fact, there are e.g. a gazillion proxy servers written in Python.
Look no more. I posted an example in the X2 repository, under the directory network/webproxy. The code is written for clarity and not for performance. In fact, fancy error handling is even omitted (minimalism rulez!). There is no support for pipelining, or in-memory cache, or per-connection thread, or even secure connection via https. I leave them as exercises for the curious readers.
If we focus on things which work, here they are: asynchronous socket handling, different request methods (GET/PUT/POST/HEAD), persistent connection aka keep alive, and even Flash and HTML 5 video streaming. Yes, you can still watch YouTube or Vimeo if you hook your browser into this little proxy. For a few hours of hacking and 92 lines of code (as reported by sloccount) and certain ways to abuse QObject, I could not be more happier.
There will be two other offspring examples based on this one. So stay tuned. Meanwhile let's just hope nobody would ask me for a colorful UML diagram for this snippet...
PS: Special thanks to Jan Erik for his feedback and review.
Friday, March 26, 2010
multiples of 3 or 5
One day Helder showed me Project Euler, a collection of interesting math problems to be solved using computer programs.
I took a look at the first problem: find the sum of all the multiples of 3 or 5 below 1000. Getting the linear time solution was trivial, the constant time solution was also not hard. However, I could not help it, I continued by applying some obfuscation voodoo and came up with this answer (of course, constant time as well):
return "uncopyrightable"[n % 15] - 'a' + 44 - "xzoxy}pge]_LAKD"[n% 15] +
'A' - (!(n % 15)) * 9 + 15 * ((n / 15) * (4 + ("aaabbcdddeffggg"[n % 15] - 'a')) +
(n / 15) * (n / 15 - 1) * 7 / 2);
How did a word ("uncopyrightable") end up in that solution? Believe me, it was (a lot of) fun! :)




