Friday, June 21, 2013

JavaScript convert signed integer to unsigned integer or Int32 to UInt32

Try this in your browser:

    document.write((1 << 31));

What do you get? Is it -2147483648?

So, why is it negative? The reason for this is that JavaScript Bitwise Operators convert your number into 32 bit signed integer. 

The trick and absolutely the simplest and fastest to flip between int32 and uint32 is to use zero-fill right shift like this:

    document.write((1 << 31) >>> 0);

Voila! This time you'll get 2147483648? Simple? Keep in mind that doing >>>0 again will flip uint32 back to int32.

Friday, May 3, 2013

FileSystem inspector in Chrome Dev Tools

I love Chrome, but some features are hidden so deep that if you find them once, you are not sure you'll remember where there were.

So, you are playing with HTML5 FileSystem API and you need to see if Chrome created/saved/deleted your files or folders. There are few tricks that suppose to make your life simpler, but ... they didn't work for me because I my application is not a regular web page but Packaged App. That's why I was so happy to see that Chrome Developer Tools now include FileSystem inspector.

Here is how to enable FileSystem inspector:
- Go to chrome://flags/ and enable "Enable Developer Tools experiments"
- Restart Chrome
- Open Developer Tools and click on Resources tab.
- Click Setting (gearwheel icon at the bottom right corner), then "Experiments", and then "FileSystem inspection":

- You may need to restart Chrome again. After that you should see "FileSystem" option on "Resources" tab:


Thursday, April 18, 2013

Peeper Flash plugin in Chromium on Linux (Ubuntu)

Let's say you installed Chromium into your $HOME folder and discovered that there is no Flash plugin.
The solution is simple.
Step 1: Get Google Flash Plugin for Linux. See reference to other post at the end.
Step 2: Run chromium with command line switch "--ppapi-flash-path"

$HOME/chrome-linux/chrome --ppapi-flash-path='$HOME/chrome-linux/'

I borrowed that idea from this post, so all credits should go there. You can find more details there as well.

-= Oleg =-

Thursday, April 4, 2013

Mini PC - MK809 - USB Driver not recognised by ADB

It took me a while to figure out how install USB driver for MK 809, but I did it. And I did it several times using different methods because I couldn't make adb to recognise it. Finally, I came across the post that suggested to add driver vendor ID  to the "C:\Users\<your username>\.android\adb_usb.ini" file. I did it and it WORKED!!! Here is it looks:

# USE 'android update adb' TO GENERATE.

0x2207 MiniPC driver

I'm so happy I can now debug my application on Mini PC from Eclipse. The only sad part is that my application requires WIFI and what I discovered is that when you check "USB / Connect to PC" in Android settings, then WIFI gets disabled. This seems like a limitation of this tiny device :(

-= Oleg =-

Tuesday, April 2, 2013

How to fix "Android Fix: Eclipse is loading framework information and the layout library from the SDK folder. main.xml will refresh automatically once the process is finished."

I started seeing this error after I installed additional SDK versions. I tried the following:
  • Create a new workspace as suggested in this form post. This didn't make any difference.
  • Looked if I had any older versions of SDK jar files as outlines in this blog post. It appeared that I didn't have any older jar files installed.
  • On a layout designer page, change the Android version used for rendering the layout (see top right corner of the designer window). That didn't help either.
  • Reinstall SDK as suggested here. That actually worked, except that I had to do it slightly differently.
To recap, reinstalling SDK solved the problem for me. BTW, I'm on Android SDK version 4.2.2 and I'm using Eclipse IDE. Here is how to reinstall SDK in Eclipse:
  • open Android SDK Manager. There is an icon in toolbar if you have Java perspective open.
  • Close Eclipse (not sure is this is needed, but that's what I did)
  • Check "SDK Platform" from the latest installed SDK (Android 4.2.2 in my case). 
  • Click "Delete packages". Wait for it to finish,
  • Check "SDK Platform" and all other items that were uninstalled in the previous step.
  • Click Install packages.
  • Start Eclipse.
Good luck!

Wednesday, July 18, 2012

FlashDevelop - "Error Definition starling.core:Starling could not be found." - SOLVED

Go to Project Properties, Classpath tab and add/edit the classpath to Starling classes.  Specify path to the src folder like this:



Monday, April 30, 2012

How to run sudo application on startup in Ubuntu without asking for password

Option 1 - Startup Applications

Step 1: Use Ubuntu UI for configuring Startup Applications. Depending on the Ubuntu version you can either go to System > Preferences > Startup Applications or type "Startup Applications" in Dash. From there you can simply edit the list of applications that you want to run on startup. More about Startup Application UI.

Step 2: Configure your application to start with sudo without asking for password. For that you need to add your application to the list of sudoers and disable  password just for your app. Let's open the sudoers configuration file. This can be done with visudo command like this:
sudo visudo

The reason visudo commend is recommended over using a regular text editor is because it locks sudoers configuration file while you are editing it.

Now let's say your user name is user1 and app name is my_app.jar, then add the following line to the configuration file:
user1 ALL=NOPASSWD: java -jar /usr/local/my_app.jar

All done. Now you can restart Ubuntu and enjoy your app running.

Option 2 - Add your app to rc.local

Option 1 will start your application only after user has logged in. What if need to start your application before that or regardless if user has logged in or not? The one of the simplest options is to add your application to the rc.local file. Open editor:
gksu gedit /etc/rc.local

And add your command to execute application just before the exit 0 statement.

Option 3 - Run your app as a Service

Most common approach in Linux world is to add your app to the /etc/init.d script. You can do the same in Ubuntu too, but Ubuntu has something even better. It's called Upstart. You can find the mode details on how it work in this blog post and on Ubuntu help page.

The beauty of this approach is that you can easily control your service from command like using start and stop command. It also allows you to configure dependencies on other services.