Thursday, 9 September 2010

Testing Google Instant

Google Instant was released today, for a certain subset of users only. Google announced in their blog post that Google Instant is a new means of "googling". Instant search means that you only have to type a few letters of your search query, and Google search will instantly show you search results (before you press the enter key). As you enter more letters, the search results will instantly update, without having to reload the page. This search system was developed using JavaScript in the front end, along with Google's highly developed and fast search system behind it all. Query times of 0.3 seconds are very significant when your search results are updating as every character is typed!

Please note: This post is a test for Google Instant. I went to google.com, typed in "testing" and one of the top suggestion results was "testing google instant". I'll test and see if this blog post appears in the results quickly.

Tuesday, 31 August 2010

Book Review - The Shadow Of The Bear (Regina Doman)

The Shadow of the Bear

by Regina Doman
The Shadow of the Bear

Description

When Bear, a mysterious young man, lands on Blanche and Rose Brier's doorstep in New York City, the two sisters have conflicting opinions on whether or not he is dangerous. Even as Blanche learns to trust him, her fears that Bear's friendship threatens their family prove terrifyingly true. A modern retelling of the classic Brothers Grimm fairytale.

Read more on Amazon...

Personal Review

This book is a classic - one that I've read many times and will read again. The adaptation of the fairy tale "Snow White and Rose Red" is set in modern New York City, and fits in very well with this environment. But don't think this is just a children's fairy tale - anyone who has read Chesterton or is versed in classical literature will appreciate the quotes that come up throughout the story in casual conversation. The characters are engaging and varied - some are drug dealers, some classical poets, while others appear to be both! And surprisingly all the dialog sounds natural, despite dealing in some depth with many aspects of faith and life.

Some of the topics covered in a unique and realistic manner include modesty, judging people, revenge and peer pressure. You might think that having such a strong Christian moral the storyline would be weak - quite the opposite! The action and events in this story themselves make for a great read, the moral values simply add to this book's appeal.
Anyone from early teens on would definitely enjoy reading this book, although older teens would have a greater appreciation of the relationship aspects. This book is suitable for younger readers than Waking Rose or The Midnight Dancers (which deal with relationships at a higher level).

Violence (6/10) Rating: 6/10

There are some moderately violent scenes in this book. However, the level of violence seems appropriate to the story, and adds a level of realism without being overly graphic.

Some of the violent aspects include:
  • A gang of boys attack a boy and girl, and the girl is thrown to the ground
  • One character is nearly asphyxiated
  • A girl is forced into a car, and held against her will
  • People are held at gunpoint several times
  • One character is shot and wounded (not life-threatening)
  • A character threatens suicide
Anyone from early teens onward should be able to handle the level violence in this book. More conservative parents might wish to read the book first though, to be sure.

Immorality (6/10) Rating: 6/10

One of the major themes of this book is drug dealing. While innocent characters are sometimes suspected of illicit dealings, it's always very clear that using or handling drugs is wrong.

Some high school students are smoking cigarettes without permission or adult supervision. These are students with a bad reputation, and it's obvious that what they're doing is wrong.

In once scence, a boy is alone with a girl and tries to force a kiss (nothing further ensues though). This particular issue is handled very well, and later on in the book the girl gives a marvelous treatise on morality and character.

Language (1/10) Rating: 1/10

The language is exceptionally clean throughout this book, a remarkable achievement considering some of the characters involved.

SN Themes (3/10) Rating: 3/10

The characters' moral struggles feature prominently in this book, but no real supernatural themes. A Catholic church is regarded as "sacred" but this feature isn't dwelt on. There is a brief scene where the number "666" is used by the "bad guy".

Overall, the story is very light on supernatural elements, despite it's strong moral content. It's written as a fairy tale, and can be read as such.

Catholic Perspective

Catholics will love this book. The author has portrayed strong Catholic values in a way that makes sense. Anyone who comes from a Catholic background will find a lot to relate to.

But The Shadow Of The Bear also has strong appeal for Christians of any kind. The characters are current-day teenagers with many of the real-world challenges faced in this role. The specifically Catholic aspects aren't overbearing - they're just part of the characters' lives. Overall, this is a refreshing and energising book for any young Christian. It shows that belief in God is not irrelevant or boring,  and can even lead to adventure!

Read more on Amazon...

Monday, 30 August 2010

Symfony 'String could not be parsed as XML'

I was receiving this error on my symfony project (using the sfWhoIsOnline plugin):

[28-Aug-2010 21:50:54] PHP Fatal error:  Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/xxxxxxx/plugins/sfWhoIsOnlinePlugin/lib/sfWhoIsOnlineUserFacade.class.php:38
Stack trace:
#0 /home/xxxxxxx/plugins/sfWhoIsOnlinePlugin/lib/sfWhoIsOnlineUserFacade.class.php(38): SimpleXMLElement->__construct('')
#1 /home/xxxxxxx/plugins/sfWhoIsOnlinePlugin/lib/filter/sfWhoIsOnlineFilter.class.php(14): sfWhoIsOnlineUserFacade::registerUser(Object(myUser))
#2 /home/xxxxxxx/cache/frontend/prod/config/config_core_compile.yml.php(1026): sfWhoIsOnlineFilter->execute(Object(sfFilterChain))
#3 /home/xxxxxxx/plugins/sfDoctrineGuardPlugin/lib/sfGuardRememberMeFilter.class.php(56): sfFilterChain->execute()
#4 /home/xxxxxxx/cache/frontend/prod/config/config_core_compile.yml.php(1026): sfGuardRememberMeFilter->execute(Object(sfFilterChain))
#5 /home/xxxxxxx/cache/frontend/prod/config/config_core_compile.yml.php(990): sfFilterChain->execute()
#6 /home/xxxxxxx/cache/frontend/prod/config/config_core_compile.yml.php(1026): sfRenderingFilt in /home/xxxxxxx/plugins/sfWhoIsOnlinePlugin/lib/sfWhoIsOnlineUserFacade.class.php on line 38
[29-Aug-2010 00:06:48] String could not be parsed as XML
[29-Aug-2010 02:14:47] String could not be parsed as XML

Turns out, SimpleXMLElement can't handle empty strings or badly encoded documents well. As a patch of sorts, I replaced the code at line 38 in the sfWhoIsOnlineUserFacade class with the following lines (original lines in bold):

/* Begin Hack to fix error 'String could not be parsed as XML' */
try {
  $xml = new SimpleXMLElement($xmlString);    // <-- Original line 38   
$instance->fromXml($xml);                // <-- Original line 39
} catch (Exception $e) {
  sfContext::getInstance()->getLogger()->crit('sfWhoIsOnline failed to create SimpleXMLElement');
  sfContext::getInstance()->getLogger()->crit('xmlString: '.$xmlString);
}
/* End Hack */

References:
http://drupal.org/node/541892
http://weierophinney.net/matthew/archives/111-mbstring-comes-to-the-rescue.html
http://www.google.com/search?hl=en&q=String+could+not+be+parsed+as+XML&aq=f&aqi=&aql=&oq=&gs_rfai=
http://ketarin.canneverbe.com/forum/viewtopic.php?id=384

Sunday, 22 August 2010

Undelete a Linux file

Undelete! | Atomic Object, Software Design & Development:
How to undelete a file removed with the 'rm' command on Linux
"grep -a -B 25 -A 100 'some string in the file' /dev/sda1 > results.txt

Thursday, 19 August 2010

Install phploc on openSuSE 11.3 [HOWTO]

Once you've got PEAR installed, run these commands (as root):

pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear install phpunit/phploc


At first I was getting errors:

phpunit/File_Iterator requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/phploc requires package "phpunit/File_Iterator" (version >= 1.2.0)
No valid packages found
install failed


But running:

pear upgrade-all


fixed all the errors.

Monday, 9 August 2010

Use ssh-copy-id on a non-default port

ssh-copy-id has known problems with handling non-standard ports (e.g. connecting to a different port than 22). To overcome this issue, use a command like:

$ ssh-copy-id "user@host -p 6842"

Source:http://it-ride.blogspot.com/2009/11/use-ssh-copy-id-on-different-port.html

Wednesday, 7 July 2010

[FIX] Migrate Windows Server 2003 to VMWare ESXi fails to boot - white non-flashing curser

I recently used VMWare Standalone Converter to migrate a physical Windows Server 2003 machine to a Virtual machine Infrastructure host. However, the machine would not boot up on ESXi 4. All that appeared on the screen was a white, non-blinking cursor at the top left of the screen.

Turns out, after a lot of troubleshooting, that ESXi can't handle virtual IDE drives - they must be SCSI, either LSI Logic or Bus Logic. After following this guide to setup SSH on ESX server, I then followed the instructions at the VMWare help site to convert the virtual IDE disk to SCSI (with LSI Logic controller). I used vi to edit the required file, as nano is not available on ESXi.

After the conversion was complete, the machine booted perfectly.

Thursday, 24 June 2010

Symfony / sfGuardUser: MySQL errno: 150 Failing Query "ALTER TABLE sf_guard_user......."

I've been trying to link up my symfony project (using Doctrine) to sfGuardPlugin with profiles. However, when trying to rebuild the schema and insert sql, I encountered the following error:

SQLSTATE[HY000]: General error: 1005 Can't create table 'phoenix.#sql-740_d7' (errno: 150). Failing Query: "ALTER TABLE sf_guard_user_profile ADD CONSTRAINT sf_guard_user_profile_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id)". Failing Query: ALTER TABLE sf_guard_user_profile ADD CONSTRAINT sf_guard_user_profile_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id)


This isn't an incredibly useful error message. Turns out that it's to do with the way MySQL handles cascading constraints. To cut a long story short, there's more info in the links posted below, but basically you need to remember that "type: integer" does not mean it will be stored as INTEGER in MySQL. As a matter of fact, "type: integer" in a schema.yml file translates into a "BIGINT(20)" in MySQL - which means when you add a constraint to a normal INTEGER field, it fails.

To store an integer value in schema.yml, use "type: integer(4)". This will translate into a type of INTEGER in MySQL.

Explained in a comment I found:
Something you might be interested in, that took me quarter an hour. integer(11) in schema.yml does not result in int(11) in MySQL, but instead you have to write integer(4) in your schema.yml. integer integer int/serial integer(1) tinyint smallint/serial integer(2) smallint smallint/serial integer(3) mediumint int/serial integer(4) int int/serial integer(5) bigint bigint/bigserial However, in my case integer without a number resulted in BIGINT.


More info:
http://trac.symfony-project.org/wiki/sfGuardPluginExtraDocumentation
http://mirmodynamics.com/post/2009/04/02/SQLSTATE%5BHY000%5D%3A-General-error%3A-1005-Can-t-create-table-*-%28errno%3A-150%29 (especially see the last comment)
http://bytes.com/topic/mysql/answers/865699-cant-create-table-errno-150-foreign-key-constraints

Friday, 4 June 2010

WeReward brings incentive advertising to iPhone

This is a Sponsored Post written by me on behalf of IZEA. All opinions are 100% mine.


Chops WeReward (WeReward.com) is a new iPhone app from Izea (the makers of PayPerPost and Sponzai, among various similar services).

Their latest offering is basically a way for iPhone users to make money by performing small, easy-to-do actions on their mobile device. The application integrates with Facebook, Twitter and Foursquare, and offers a variety of incentiv-ized postings.

According the the official website:
Earn WeReward points by completing tasks and checkins at your favorite businesses with your iPhone. Each point is worth a penny, earn 1,000 points and cashout to PayPal.
1000 points is equal to $10 at that conversion rate, which is pretty decent. Of course, it will take a long time to make much money when you're getting paid one penny for each tweet/checkin/share. But it all adds up.

The key to this application succeeding is the location-based relevance. Because offers are tailored to your location, many of the offers you see will actually be useful. In fact, your friends may find your posts helpful, because in many cases they are things that you would already be posting about anyway.

If you can get paid to do stuff that's useful to your friends, and takes little or no extra effort on your behalf, what's the catch? Nothing, really. If you're prepared to take a small amount of time and risk your reputation posting advertisements on your profile, there's nothing else that could really go wrong. Personally I would do it - provided the offers are relevant.

If you have an iPhone you can Download the App today - it only takes a minute. I'd love to hear your feedback (as I don't have an iPhone myself - I use Android). It's something I would definitely use myself, and helps to progress the whole micro-payments infrastructure. Interesting also that they use PayPal for payments. This is a sensible choice, but given MasterCard's entry into the market is something that could change relatively quickly.

Check out the video of how it works in action:

Visit my sponsor: WeReward for iPhone

Wednesday, 2 June 2010

Javascript Card Guessing Game - Sample Code

I've been doing some coding in Javascript lately, and thought I would share some of the code I've been writing. Hopefully some of it will be useful for anyone looking for some sample code in Javascript, or examples of looping, keeping tallies, or writing basic functions.

Without further ado, here is the code. It's a simple playing card guessing game.
Javascript Card Guessing Game

Tuesday, 1 June 2010

Android: Using Accelerometer to Calculate Total Force

I'm in the process of building an app that calculates how far you could throw something, based on the speed you swing your phone. This involves tracking your phone's movement as you swing it, and calculating the total maximum force involved. I couldn't find any examples on how to do this, so I've mocked up a bit of a tutorial below.

How do we get the accelerometer values?

private SensorManager mgr=null;
mgr=(SensorManager)ctxt.getSystemService(Context.SENSOR_SERVICE);
mgr.registerListener(listener,
mgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_UI);



private SensorEventListener listener=new SensorEventListener() {
        public void onSensorChanged(SensorEvent e) {
            if (e.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
                //Total acceleration will be sqrt(x^2+y^2+z^2)
                double netForce=e.values[0]*e.values[0];    //X axis               
                netForce+=e.values[1]*e.values[1];    //Y axis
                netForce+=(e.values[2])*(e.values[2]);    //Z axis (upwards)
               
                netForce = Math.sqrt(netForce) - SensorManager.GRAVITY_EARTH;    //Take the square root, minus gravity
               
                Log.d("ForceCalculator", "Net force:"+netForce+"");
            }
        }
       
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // unused
        }
    };


This will create and register an event listener for the accelerometer. This listener then calculates the net force.

This calculation is pretty self-explanatory. It involves three components - X axis, Y axis, and Z axis. To calculate the magnitude of these vector components, we simply take the square root of their combined squares:
netForce = sqrt( x^2 + y^2 + z^2 )
The only point to note is that we then subtract the acceleration due to gravity (approx. 9.8m/s^2). Otherwise we could have a resting acceleration of +9.8.

Full code will be coming later, when I've got some more time to play around with it. For now, this should show you how to get net force using the accelerometer. Still to come is code to calculate maximum force over a specified period of time, with threshold starting and finishing velocities.

Wednesday, 26 May 2010

How to lock & unlock the KDE4 screensaver from command line

Here are two DBUS commands you can use to start or stop the KDE4 screensaver (previously known as kscreensaver or kscreenlock) from the command line.
Enter one of the following two commands into your linux shell (bash):

Lock:
dbus-send --type=method_call --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.Lock

Unlock without password:
dbus-send --type=method_call --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SetActive boolean:false

Both these commands work with the latest KDE 4.3.5

Friday, 14 May 2010

HOW TO Install MetaTrader 4 on Linux

How to run Meta Trader 4 on Linux using WINE.
  1. Sign up for an account at a forex broker, and download their MT4 installer. I used Easy-Forex, but this procedure should work for any version of Meta Trader 4.x.
  2. Install wine on your linux machine (I used wine 1.1.44 on an openSuSE 11.2 machine). Also download winetricks (used to install additional libraries required by MetaTrader).
  3. If you haven't used wine before, run 'winecfg' to create your installation directory. You can then click 'OK' to exit the dialog, or have a look around at the options (I used the defaults).
  4. Start up a Windows computer, and copy all the files in C:\WINDOWS\Fonts into the wine directory (/home/username/.wine/drive_c/windows/Fonts)
  5. Run winetricks to install mfc40 and mfc42:
      sh ./winetricks mfc40 mfc42
  6. Run the MetaTrader installer executable.
       wine ./mt4setup.exe
That's it! You should now be able to run MetaTrader4 by clicking on the icon on the desktop, or running the following command in your Linux shell:

wine /home/username/.wine/drive_c/Program\ Files/yourmt4installdirectory/terminal.exe

If you have any more problems or questions, please contact me by leaving a comment. MetaTrader is running fine for me under openSuSE 11.2 with the latest WINE from the repositories, once MFC40, MFC42 and the correct fonts had been installed.

More information:
http://appdb.winehq.org/objectManager.php?sClass=version&iId=2893
http://www.aboutcurrency.com/university/metatrader/installing_metatrader4_under_linux.shtml
http://easyforextrading4u.com/metatrader-linux/

Appendix:
When you first start MetaTrader4, it might take a while to initialise. You'll see something like the following in the shell output:

fixme:reg:GetNativeSystemInfo (0x58c4c8) using GetSystemInfo()
fixme:toolhelp:CreateToolhelp32Snapshot Unimplemented: heap list snapshot
MetaQuotes Language 4 compiler version 4.00 build 224 (14 May 2009)
Copyright 2001-2009, MetaQuotes Software Corp.

Exp file "Z:\home\david\.wine\drive_c\Program Files\MT4 at easy-forex\experts\MACD Sample.ex4" produced - 0 error(s), 0 warning(s)
Xlib: extension "Generic Event Extension" missing on display ":1000.0".
fixme:reg:GetNativeSystemInfo (0x58c4c8) using GetSystemInfo()
fixme:toolhelp:CreateToolhelp32Snapshot Unimplemented: heap list snapshot
MetaQuotes Language 4 compiler version 4.00 build 224 (14 May 2009)
Copyright 2001-2009, MetaQuotes Software Corp.

Exp file "Z:\home\david\.wine\drive_c\Program Files\MT4 at easy-forex\experts\Moving Average.ex4" produced - 0 error(s), 0 warning(s)
Xlib: extension "Generic Event Extension" missing on display ":1000.0".
fixme:reg:GetNativeSystemInfo (0x58c4c8) using GetSystemInfo()
fixme:toolhelp:CreateToolhelp32Snapshot Unimplemented: heap list snapshot
MetaQuotes Language 4 compiler version 4.00 build 224 (14 May 2009)
Copyright 2001-2009, MetaQuotes Software Corp.

Exp file "Z:\home\david\.wine\drive_c\Program Files\MT4 at easy-forex\experts\indicators\Accumulation.ex4" produced - 0 error(s), 0 warning(s)
Xlib: extension "Generic Event Extension" missing on display ":1000.0".
fixme:reg:GetNativeSystemInfo (0x58c4c8) using GetSystemInfo()
fixme:toolhelp:CreateToolhelp32Snapshot Unimplemented: heap list snapshot
MetaQuotes Language 4 compiler version 4.00 build 224 (14 May 2009)
Copyright 2001-2009, MetaQuotes Software Corp.


Some errors I was encountering before installing the mfc40 and mfc42 libraries:

err:module:import_dll Library KERNELBASE.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-Debug-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-ErrorHandling-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-File-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-Handle-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-Interlocked-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-LibraryLoader-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-Localization-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-LocalRegistry-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-Memory-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-Misc-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-ProcessEnvironment-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-ProcessThreads-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-Profile-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-String-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-Synch-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library API-MS-Win-Core-SysInfo-L1-1-0.dll (which is needed by L"C:\\windows\\system32\\MFC42.DLL") not found
err:module:import_dll Library MFC42.DLL (which is needed by L"Z:\\home\\david\\.wine\\drive_c\\Program Files\\MT4 at easy-forex\\MetaEditor.exe") not found
err:module:LdrInitializeThunk Main exe initialization for L"Z:\\home\\david\\.wine\\drive_c\\Program Files\\MT4 at easy-forex\\MetaEditor.exe" failed, status c0000135

Thursday, 29 April 2010

Dual Monitor VNC on Ubuntu - with scaling

To get dual-monitor remote desktop over VNC working withUbuntu, I had to install x11vnc. With the default VNC server, only half of my desktop would appear with the other half blacked out. Also, the whole two screen layout would not fit within my VNC client window.Ultimately this is the command I came up with the start the VNC server:

x11vnc -xinerama -xwarppointer -scale 3/4 -noxdamage -ncache 10

The first two arguments setup dual screen mode. The next one (-scale 3/4) scales the screen to 3/4 of it's original size (the scaling is done server-side). The -noxdamage argument prevented some annoying server errors that were appearing. And the -ncache 10 option enables client-side pixel caching, which speeds up things considerably.

References:
http://ubuntuforums.org/showthread.php?t=535574
http://ubuntuforums.org/archive/index.php/t-252888.html
https://help.ubuntu.com/community/VNC?action=show&redirect=VNCOverSSH