Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.   |    "Nothing can stop the man with the right mental attitude from achieving his goal; nothing on earth can help the man with the wrong mental attitude." - Thomas Jefferson   |    "We are still masters of our fate. We are still captains of our souls." - Winston Churchill   |    "Our doubts are traitors, and make us lose the good we oft might win, by fearing to attempt." - William Shakespeare   |    "Perl - The only language that looks the same before and after RSA encryption." - Keith Bostic   |    "Take calculated risks. That is quite different from being rash." - George S. Patton   |    "Good luck' follows careful preparation; 'bad luck' comes from sloppiness." - Robert Heinlein   |    "We are what we repeatedly do. Excellence, therefore, is not an act but a habit." - Aristotle   |    "The more you learn, the more you need to learn." - Robert Heinlein   |    "Nothing great was ever achieved without enthusiasm." - Ralph Waldo Emerson   |    "There is no such thing as luck; there is only adequate or inadequate preparation to cope with a statistical universe." - Robert Heinlein   |    "The talent of success is nothing more than doing what you can do, well." - Henry W. Longfellow   |    "Every artist was first an amateur." - Ralph Waldo Emerson   |    "Nothing will ever be attempted if all possible objections must first be overcome." - Samuel Johnson   |    "Success is the sum of small efforts, repeated day in and day out." - Robert Collier   |    "If Java had true garbage collection, most programs would delete themselves upon execution." - Robert Sewell   |    "The big secret in life is that there is no big secret. Whatever your goal, you can get there if you're willing to work." - Oprah Winfrey   |    "The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be" - Horace Bushnell   |   

Code Reactor

The best of modern Web development

Facebook PHP compiler

More and more php compilers are emerging, and it now finally looks like there are a number of decent ones out there.

Just a couple of years ago, there only were bcompiler, eaccelerator and perhaps some others, but none really good. Eaccelerator would be sensitive to server environment and only work under certain conditions, and even have special problems with different php programs, and others had similair problems.

But now it seems like there are 5-10 different compilers, and all seem to work really nice. An especially interesting one is HipHop for PHP – a php compiler written by facebook to run in their own servers. The ultimate goal of all compilers is the SPEED (and, hwell, perhaps, obsfucation too), and I can only imagine what kind of speed problems the facebook experiences, with all their traffic, so if hiphop is good for them, then it should be too for the rest of the normal mortal aplications out there.

One important thing to know though is that hiphop for PHP is not an opcode cacher or a JIT. It is actually a compiler, and produces binary code as such. Probably because of that it has problems with eval() and some other dynamic features of PHP. If that is the case with your application, then it’s probably not for you, but how often does one really use eval?

Definetely check it out if you are looking to speed up your php application without changing a line of code. http://developers.facebook.com/blog/post/358/

Github: https://github.com/facebook/hiphop-php/wiki/



Anonymity in 2010

A great podcast/presentation that has started to circulate around the blogosphere, about how the internet and the progress is affecting our anonymity.

Steve Rambam (who is/was a private investigator, and ironically looks very much like one, thou also like an italian mafia boss) takes on many interesting things in this 3 hour long talk, including
– What information we are putting in “The Database” ourselves and how the way people are disclosing information about themselves changed over the past 10 years.
– Just how much information does a mobile phone broadcast about its owner.
– How easy it is nowadays for a detective to find out anything about you without leaving his or her desk.
– What kind of databases are being put together, sold and used, and what kind of information can be found there.
– A couple of interesting sites for information hunting.

tolua++ windows precompiled binary exe file download and more instructions on tolua++.

So, since the last post, I have started embedding lua and has had some minor problems.

First I tried using luabind, which didn’t work at all for me. I didn’t want to include and build both luabind and boost (which it requires), and all of the precompiled solutions didn’t work either on my setup for different reasons, plus I just didn’t have time nor motivation to spend an hour trying to setup paths, projects, solutions, includes and so on for a library which should be precompiled.

So I thought screw luabind and I will go with tolua++. Which does almost the same thing but in a different way. Basically, luabind is like a library with a lot of macros, which you use to define your bindings in certain way in your code, and when the macros get expanded before compilation, the bindings start working. Tolua++ (and its predecessor tolua) on the other hand, only includes a very small runtime library, and most of the work is done before compilation by an external command line tool. It takes in special header files which you must write for your bindings and converts them to cpp files which you then include into your project like any other cpp file, and all the bindings are defined there. (This step is automated of course, you only define the special header and include the output file once).

tolua++ doesn’t require boost, which would mean less trouble compiling it, and also I thought that the exe file itself would be just downloadable precompiled.

However it wasn’t. But now after some time figuring out the compilation routine, I have compiled it and thought that I can put it out here for everyone who wants to save an hour or so by just fetching the file which should have been available from the author’s site from the beginning.

Anyways, here is the binary. It is for win32 and is tolua++ 1.0.93:

tolua++ 1.0.93 compiled binary (exe).

When compiling this, I have had a great help from this guide: http://lua-users.org/wiki/CompilingToluappWithoutScons

Although some things in that guide seemed to be incorrect, so here is my modified version: Tolua++ compilation guide.

As for actually using the tolua++, here is another awesome guide which should get you started: http://www.icynorth.com/forums/viewtopic.php?t=301

Compiling Tolua++ 1.0.93 without SCons (updated)

This guide is based on the http://lua-users.org/wiki/CompilingToluappWithoutScons
I just have modified some things in the Visual Studio part, because in the original, the steps didn’t work for me.

So, needless to say, most credit goes for the author of the original guide, I have just modified some stuff!

I wanted to post this on the tolua++ site but they dont have a wiki.

The tolua++ INSTALL file lets you figure out how to compile it without SCons. Its easy enough, but I wanted to save the people the 5 ( err… 15 ) minutes they need to figure this out.

Using GCC/Mingw

I am using gcc 3.4.2, on a mingw installation. But I think this should work for most people, at least those using gcc, with minor modifications.

The commands used are :
tolua++_1.0.5\src\lib> gcc -shared -o tolua++.dll *.c
\Lua502.dll -I..\..\include -I
\include
– This will create the dynamic library tolua++.dll in the src\lib directory.
tolua++_1.0.5-1\src\lib> gcc -c *.c -I..\..\include -I
\include
tolua++_1.0.5-1\src\lib> ar rcsv libtolua++.a *.o
– This will create the static linking library in the src\lib dir.
tolua++_1.0.5\src\bin> gcc tolua.c toluabind.c -I..\..\include -I
\include
\Lua502.dll -L..\lib\ -ltolua++
– This creates the tolua++ executable in the src\bin dir, assuming the libtolua++.a was created in the src\lib dir.

Note1: If you are linking against the lua static library instead of the dynamic library, replace
\Lua502.dll with -L
\lib -llua .

Using Visual Studio 2003

Library (.DLL/.lib)

Open the “File->New Project” menu. From the project types listbox, select “Visual C++ Projects->Win32”. From the Templates listbox, select “Win32 project”. For a project name, type in “tolua++”.

When the wizard opens, select “Application Settings” on the right hand side. Choose “DLL” and click ‘Finish’. If you want to compile to a static library, choose Static Library (.lib)

In the Solution Explorer right click on “source files” and select “Add->Existing Item”. Browse to the location of the tolua++\src\lib directory. Highlight all .c and .h files and add them to the project. You may also optionally want to add the tolua++.h file from the include directory into the “header files” folder.

Right click on the tolua++ project in the Solution Explorer and select “Properties”.

Under the “C/C++ -> General” section select the “Additional include directories” option. Navigate to the location of your Lua include files.

Under the “C/C++ -> Preprocessor” section add the following: TOLUA_API=extern __declspec(dllexport) Under the “C/C++ -> Precompiled headers” section, turn off precompiled headers. Under the “Linker -> General” section select the “additional library directories” option and navigate to the location of your Lua .lib library files. Under the “Linker -> Input” section add lua.lib and lualib.lib (assuming those are your lua libraries).
In more recent versions of lua there is just one library, for example “lua5.1.lib”. In that case, just include that.

Compiling the project should result in a tolua++.dll. or tolua++.lib, whichever you chose in the project settings.

Executable (.exe)

Now, to build the executable, you must first build the library. And even thou there is probably some way to do this using the .dll for of the library, it’s easier to do it with a static one. So before compiling the executable, first compile the library as a static library (not as .dll (project settings)), to get a proper .lib file.

To create tolua++.exe, open the “File->New Project” menu, select Visual C++-> Win32 -> Win32 console project. Add the files “tolua.c”, “toluabind.c” and “toluabind.h” to the project. (NOT toluabind_default.*)

Similarly to the previous step, add the lua .lib include directory (in project settings – linker – additional library directories) and the lib itself (project settings – linker – input (just write the library filename there (no path)))

If you have listened to my advice and linked the tolua++ library statically, don’t add anything in the “C/C++ -> Preprocessor” section. If you went with dll, you will probably have to add
“TOLUA_API=extern __declspec(dllimport)”

(NOTE: this is not the same line as in previous step. That one was with dllEXPORT).

Note that for v1.0.92, I had to remove the TOLUA_API that appears in toluabind.c:
int TOLUA_API tolua_tolua_open (lua_State* tolua_S)
becomes
int tolua_tolua_open (lua_State* tolua_S)

Update: For 1.0.93 with static linking, I didn’t have to remove anything like that. So don’t worry about this unless you get compiler errors.

Using Visual Studio 2005

The same comments as above (for vs2003) generally apply, although some minor tweaks need to be made.

Note that, due to VS’ poor c99 support, ‘toluabind.c’ in the “EXE” build will not compile. There are many lines that look like:

… int top; top = lua_gettop(tolua_S); static unsigned char B[] = { …

These need to be changed to:

… int top = lua_gettop(tolua_S); static unsigned char B[] = { …

or similar.

Tested with vs2005 (no service packs) and tolua++ 1.0.91.

Codereactor update: Had no problems like this in VS2008, so maybe this is not the problem at all anymore.

You can also download the precompiled executable from here: tolua++.exe precompiled executable download.

As for the precompiled library, I advice you not to bother. Tolua++ is just a couple of c files, just include them into the sources in your project, and forget about all that library inclusion hassle.

Embedding a scripting language in your own C++ programs

One of my current projects has gained the critical mass complexity that can justify an embedding of a scripting language, so that some parts of the projects can be flexibly scripted instead of being hardcoded into the C++ code and thus require a time-consuming compilation every time anything changes.

After reading a little about this, I found out that there are a lot of options, and most of them are really easy!

My first idea was to have two different programs, one in C++ and the other one in PHP (but any other multipurpose script language would suffice), and make them communicate with each other. The best choice for communication would the TCP/IP sockets, and interface could be coded pretty easily. Each function that needed to be exported, could easily be mapped through the network code. Two different programs could even be located on different machines and easily connect through the net.

This solution is possible, and is not that bad actually, but it can get pretty annoying to have two different programs to run and maintain.

So there I came upon the Real solution.

The two script embedding options I liked the most were Lua and JavaScript engine spidermonkey.

Lua is an opensource scripting language, which is very easy to embed and is being used worldwide mostly in games to script the gaming logic. It’s biggest advantage is the speed. By checking different benchmarks, I found out that lua code can be just around 30 times slower than c++ code, which is VERY fast for a scripting language. (For comparison, php is like 300-400 times slower, perl is something like 100-300 times, and Java approx. 10 times).

With this speed, some pretty complex calculations could be easily done in lua, instead of being hardcoded. The other advantage is that lua is semantically extensible, which means that it has very few features out of the box, but you could easily implement almost any paradigm or design pattern, whichever is most suitable for your application.

For example, there are no classes in their usual meaning in lua, they are instead “implemented” in code. When using lua, you are not only writing programs, but also sort of create your own language as you go.

As for embedding, with a small additional opensource library (of mostly macros) Luabind, binding functions and classes of your c++ program to lua becomes a piece of cake. It almost comes down to 1 extra line of code per mapped function, really smooth.

The second option I am considering is JavaScript spidermonkey, which is an embeddable JavaScript engine from Mozilla.

It would be great to have JavaScript in my project, since it’s awesomely flexible, wide-spread and very easy to code in, having a common syntax. Also, for most web developers, JavaScript is a language where you know every class and every function already.

The downside is the speed (approx. 300-400 times slower than native) and the complexity. Also, since the language itself is much more complex than barebone lua, embedding it to applications and mapping functions and classes from c++ can sometimes be tricky and bloated with type conversions and argument checks.

So this seems to be the pro way to do it, so that’s what I am gonna do.  (This time it’s gonna be lua but I am eager to try the spidermonkey some time also).

PS. It’s a pity I have overlooked this at first, but apparently, boost (which you should use most of the time anyway, cz its awesome) has built-in python bindings which work almost as easy (sometimes even easier) than luabind. So that’s a great alternative also, especially if you are a python fan.

Windows 7 aero lag fix

Windows 7 is great, but on my machine every once in a while, like after a couple of hours of working, the interface starts to lag. Nothing big, probably just 100 milliseconds or something, but it is noticeable, and especially when watching movies. Don’t really know what it is exactly, maybe something with drivers or some program that slows it down, but there are numerous reports of this out there on the internet. And this thing is really annoying, because once it has started, EVERYTHING is lagging, all the windows and everything that happens on the screen.

This has nothing to do with too little memory or some process running in background. The lag would appear even when processor usage was on 0-5 percent.

So, basically, the workaround for this: once it starts to lag, switch a window with Windows+Tab button. (To open that 3D taskswitcher that came in Vista). Once you have done that, the lag is gone.

It is sure strange, seems like there is some bug that starts when something gets overrun, and the 3D task switcher resets it to make everything run normally again.

This isn’t really a fix, just a workaround, but searching the internets gave me nothing, and this solution is still viable. So here you go people, if somebody stumbles across this article with the same lag problem, there you have a solution.

Yahoo Pipes

*** The pipes didn’t come out yesterday, so those of you who have already heard about them, can simply skip this post.

But those who didn’t, are about to find out something wonderful!

The pipes are a web service from Yahoo and can be accessed by going to http://pipes.yahoo.com/pipes/

As an example of what it can do, let’s take today’s featured pipe: eBay price watch. Apparently, it gives you information about certain items from ebay, found by certain keywords that lie in a certain price range.

Without any tools at all, finding this information would require going to eBay, searching for items, sorting, finding the ones you want, and repeating that over and over again. If you are decent programmer, you could easily make a PHP script or something that does it for you: goes to eBay, fetches a page using a search request, parses it and so on. It is doable, but is it worth the trouble?

Well with yahoo pipes a script like that takes no more than 10 minutes to create! It is all because instead of writing code, you are combining structural blocks that process information in certain ways, which can include search/replace, regexps, combining functions, well basically any kind of aggregation you could possibly imagine.

Yahoo pipes are based on RSS, so the most used output method from the pipe is an RSS channel, which, if we are talking about the eBay example, could be imported into your favorite RSS reader.

Basically any data from any webpage, RSS channel or any url can be inserted into a yahoo pipe and converted to the format you want. Several sources of data can be used, records can be combined, removed, parsed, and so on, with limitless possibilities. And, what is more important, all the above is done simply, fast and visually, which, besides the development speed, also gives you a lot of room for experimentation and creativity.

(And no, I don’t work for Yahoo, it’s just that this service is really a great contribution for human kind :P)

And I haven’t even told you the best part: Yahoo pipes support information io in JSON and if I remember correctly, even PHP-serialized, which, combined with its possibility to fetch anything that has a url, effectively means that you can create your own modules for pipes that can do anything that pipes cannot do already, making the service omnipotent.

If nothing else, it is a great way to test new ideas without having to write a single line of code.

Java compiler cares about you

There is an old anecdote, or something like a bash.org quote, which goes something like

– I really love the Java compiler, it cares so much about me
– how come?
– Well every time there is an error, it’s like “Aww, you have an error here and here, a warning here, but I can fix that by adding this and this. Here, have a cookie, sweetheart! Also I optimized these classes for you and now everything works 2 times faster”
– while vc++ compiler is like “ARGGHH! you stupid human, there is some error in those 150 files. And I don’t like the way you placed your comments here, REWRITE EVERYTHING!!! ARGHH!!!”.

It certainly seems a little like that, especially now that I’ve noticed really how much java compiler is with you even while you are coding.

1. it warns about something
2. it adds an automatic option to fix that, or even add a suppress warning
3. BUT! if you have added that suppress warning header, and there are no warnings anymore, It will warn you about having an unnecessary warning (!).
Observe: “Unnecessary @SuppressWarnings(“unused”)”.

It’s watching your every move…

Reliably importing huge mysql databases.

Every normal php web-developer will once in a while encounter a task of moving around mysql databases, or even individual tables. And if that database will be somewhat big, once again, the developer will have to deal with resource limitation problems like php execution time, memory, upload file size, and so on.

Luckily, there is a perfect solution: a php script that will import an .sql file of any size to a database, iterationally, thus automatically overcoming all of the resource limitation problems. Basically it runs itself many times, importing small portions of the file at a time, and you don’t even have to worry about that, just supply the database login info to the script, upload the .sql file to the server (by ftp for example), and press Import.
Plain and simple:
http://www.ozerov.de/bigdump.php

PS. Just remember: when you are exporting your files from the source database, uncheck the ”Extended inserts” option (in phpmyadmin or other tool), otherwise bigdump will not understand your file.

Interesting tips from Google

I was stumbling around the net and came across a couple of videos from Google’s IOs. The IO-2010 was just a couple of days ago, and a lot of interesting things were said on it, but I also found many interesting videos from their previous IOs.

This particular one (http://www.youtube.com/watch?v=6x0cAzQ7PV) is back from 2008, and even thou the internet does evolve with the speed of an atomic bomb, most of what Marissa Mayer says in the video is still true in our days.

And most importantly, what she reveals in the video is not simply some specific tips about how to build great web applications, it is also about how Google operates to really come up with those ideas.

I guess you could say that the secret is trying to touch every knob of your website, change every variable, be it functional or plain aesthetic, and trying to see what effect it does on the user experience.

Read the rest of this entry »

loading...
Your connection appears to be too slow, automatically disabling HeavyAjax (TM) for better performance...
You seem to run a browser without JavaScript support or it has been disabled. To fully experience Code Reactor please enable JavaScript. (It is not 1995 anymore :)
You seem to be using Internet Explorer. If you want to experience both Code Reactor and the rest of the web to their fullest and fastest, you are advised to download and install a real browser, like Opera, Firefox or Google Chrome.
Close
You seem not only to use Internet Explorer, which is by far a joke when it comes to browsers, but to even use an old version of it!
If you want to experience both Code Reactor and the rest of the web to their fullest and fastest, you are STRONGLY advised to download and install a real browser, like Opera, Firefox or Google Chrome.
Close