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:


Cheers!

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"
Example:

$HOME/chrome-linux/chrome --ppapi-flash-path='$HOME/chrome-linux/libflashplayer.so'

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:


# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.

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!
Oleg.

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:

C:\dev\Starling-1.1\starling\src

Cheers!

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.

-=Oleg=-

Friday, June 3, 2011

Sending bulk emails from your web application - the right way

For us, developers, it’s easy to deal with situations when your application needs to send one or two emails at a time, but is it okay to send hundreds of emails from your hosting server? Usually not and here is why.

First of all there are technical challenges. For example you have to make sure you are not exceeding the limits set by hosting providers (which are not always officially advertised).

Second and the most challenging part is getting around spam filters. If high deliverability is important to you (otherwise why would you even bother sending emails) then you need to start thinking about playing by the rules and implementing techniques like double opt-in, unsubscribe functionality and many other little things.

Unfortunately for you and fortunately for users, anti spam filters are very suspicions and it’s not that hard to get blacklisted. So if are interested in your emails being delivered into your users’ inbox, then the safest bet is let the professionals deal with that and focus on other not less important tasks.

So, now, where should you look for professional services if you need to send bulk emails? Such service is usually called email marketing. Pick carefully. There are many variations and different price points. If you don’t know where to start here are the two companies I had very good experience with: AWeber (www.aweber.com) and iContact (www.icontact.com) . As I already mentioned, I like both companies. I’d say they break even in the set of features they provide. AWeber seems to be the most popular choice - not sure why. Pricing wise iContact is a little bit cheaper, but that’s where you have to make your own comparison based on your needs.

If are not bored to death yet, I just want to mention that respectful companies like those mentioned above have API(s) for developer so if you need to send emails from your web site, you can, but now via reliable service.

Hey one more thing to consider is that email marketing companies can collects stats for you so you can actually see how many people opened your newsletter. Isn’t it cool? ;-)

Amazon ES2 Error "Configuration information could not be read from the domain controller" SOLVED

I've got this error when I tried to change the password on Windows Server 2008 running on  Amazon ES2.

The thing is, I never changed this error before even though I had to change my password many times. What was different this time is that I had problem with server and had to Stop and Start the instance. As a result the name of the instance has changed.  The problem is Remote Desktop had saved the name of the previous instance in the username field in a form "instance name\my name".

Soution:  I deleted the instance name in Remote Desktop and the error has gone away. Hurray!

-=Oleg=-

Monday, February 14, 2011

How to Vacuum Indexes (Java) on App Engine

Note, you need App Engine SDK 1.4.2 or higher.

On Linux:
./appengine-java-sdk/bin/appcfg.sh vacuum_indexes myapp/war

On Windows: 
appengine-java-sdk\bin\appcfg.cmd vacuum_indexes myapp/war

You need to run this from command line on your local PC. This command deletes all indexes for the app that are not mentioned in the local versions of datastore-indexes.xml and generated/datastore-indexes-auto.xml.

About parameters:

  • appcfg.cmd file is part of GAE SDK and so you have to look for it in the folder where SDK is installed. If you use Eclipse then App Engine plugin is installed under "eclipse\plugins\" folder. There might be several GAE SDK folders in there, so make sure you pick the right version. For example for version 1.4.2 the folder name starts with "com.google.appengine.eclipse.sdkbundle.1.4.2".

  • vacuum_indexes - name of the action.

  • myapp/war  - path to the war folder of your application. You need to specify the full path in there.


 Here is corresponding App Engine doc.

After you execute this command, it's going to ask you if you actually want to delete index or not. See screenshot below. 

[caption id="attachment_100" align="alignnone" width="683" caption="Delete index confirmation"]Delete index confirmation[/caption]

-=Oleg=-

Sunday, February 13, 2011

How to download App Engine logs in Windows

The web interface provided by admin console does not provide a lot of flexibility for analyzing your logs and sometimes you just need to have them locally to study carefully. If you are working on Windows and you feel that information provided in App Engine docs is too short, then this blog is for you.

App Engine Docs say you need to run this:

./appengine-java-sdk/bin/appcfg.sh request_logs myapp/war mylogs.txt

Well this is for Linux. If you are on Windows, here what you need to do:

  1. Find the location of the “appcfg.cmd” on your computer. I use Eclipse and in my case it was here:
    "c:\Program Files\eclipse\plugins\com.google.appengine.eclipse.
    sdkbundle.1.4.0_1.4.0.v201012021502\appengine-java-sdk-1.4.0\bin\appcfg.cmd".

  2. Find the location of your app. You need the “war” folder. Here is what I have on my machine:
    "c:\svn\mysource\myapp\trunk\war"

  3. And the final step is to put it all together. Open command prompt and type:
    "c:\Program Files\eclipse\plugins\com.google.appengine.eclipse.
    sdkbundle.1.4.0_1.4.0.v201012021502\appengine-java-sdk-1.4.0\bin\appcfg.cmd" request_logs c:\svn\mysource\myapp\trunk\war mylogs.txt


This will do the magic of downloading your application logs to your computer. Just be patient because it may take a while. In my case downloading 9 hours of logs (~1,000,000 records) took about 30 minutes.

BTW, if you don’t specify the destination folder then file is downloaded into "c:\Documents and Settings\username\" folder.

BTW2, running appcfg.cmd without parameters will show you a help page where you can read how to specify number of days and minimum log level if you need to. By default it will be 1 day of request logs only.

-=Oleg=-

Wednesday, December 2, 2009

GWT - Unicode Characters

Sometimes simple 1 minute tasks make you stop and spend 20 minutes figuring solution out.

I've got a request to replace the label "Up" by this arrow "▲" . What could be simpler? I quickly replaced "Up" by "▲" in my Java source code. Then I tried to save my code and got the Eclipse error "Some characters cannot be mapped using "Cp1252" character encoding"...

The solution is simple. I used a nice online converter http://people.w3.org/rishida/scripts/uniview/conversion.php to get the Unicode code for the arrow character and then pasted it in my Java code like this:

String upArrrow = "\u25B2";

-=Oleg=-

Thursday, October 8, 2009

GWT - best practices

GWT tutorials is a good way to learn basics and even to build simple prototypes, but it's certainly not enough information to start building real life application. That's why I was so glad to find this video from Google I/O 2009 which describes best practices for architectecting GWT application.

-=Oleg=-

Friday, October 2, 2009

New Direction - Google App Engine

As it often happened in developers life, as soon as you become an expert in something, the life throws you a new project which requires you to learn brand new  languages, platforms, frameworks, technologies, etc... Suddenly your work day routine changes from 80% coding and 20% research to 99% of learning and researching.

Only six month ago I started working with Silverlight. We had some fun playing with new power tool, we've built the a series of prototypes... and that was the end of Silverlight journey.

New mission is Google App Engine.  Our language of choice is Java. My experience with Java - none. So far looking at zillions of Java frameworks makes me dizzy. After spending 2 days on learning Struts 2 I've realized that the learning curve is expected to be very deep. I'm diving in... - wish me good luck.

-=Oleg=-

Monday, August 24, 2009

More about IIS performance

One more article about IIS performance from trusted source i.e. from Microsoft:

http://blogs.technet.com/mscom/archive/2008/06/09/microsoft-com-operations-performance-analysis-of-iis-7-0-windows-server-2008.aspx

-=Oleg=-

SVN Rollback - restoring deleted files and folders

Preface


I'm not an expert in SVN version control and I don't like using command line. I'm regular Windows user and so it was easy for me to learn how to use "Commit" and "Update" buttons in TortoiseSVN. It was easy until one day when I had to figure out how to restore delete folders.

A day when sources disappeared


One beautiful morning I checked out my sources from SVN and discovered that the most of the files and folders are gone. Apparently the night before one of the developers was cleaning SVN working folder on his machine and ... Well, if you don't know what that big red button is for it might be not a good idea to press it...

So, if don't know what to do - ask Google. Google said - don't worry, it's impossible to lose anything in SVN, just do the reverse merge using following command line params... 

The problem is I didn't want to use command line. I wanted to use beautiful TortoiseSVN UI for that. So, I found "Revert to this revision" and "Revert changes from this revision" and thought my problem is solved, but for some reason SVN was failing this task with an error "'/svn/sources/!svn/bc/373/Test' path not found". Finally, after asking an SVN expert, I figured that there was a small detail which I was missing. The revision of your working copy has to be a "HEAD".

Steps to recover deleted files or undo the submit in SVN:



  1. Get the HEAD revision from SVN it to your working folder. Working folder is the key word here. (I suggest using temporary folder)

  2. Click on Show Log

  3. In the Log window, select revision you want to undo and click on the "Revert changes from this version" in the popup menu. This will execute the merge command of the corresponding revisions.

  4. Wait for SVN to update your working folder. Working folder is the key word again. SVN updates your working folder first, so you can review the change before you commit it to SVN.

  5. Make sure your sources merged correctly and then commit the change to SVN.


Best luck recovering your sources!

-=Oleg=-

Tuesday, July 28, 2009

IIS Performance

Yesterday we had a little debate in the office about the max number or requests IIS can handle per second. So I did a little research and found that majority of the people are not able to go higher than 300-600 requests/sec, however some claim they were able to get 20000 req/sec. I guess it depends on how much processing work your request does i.e. if IIS is simply returning a HTML page or if it processes ASP.NET page doing authentication, making database requests and constructs the HTML page at the end.

Anyhow, I discovered that IIS 7  has some interesting features wich I was not aware of http://blogs.iis.net/bills/archive/2007/05/07/iis-vs-apache.aspx. I especially like the one that allows you to Troubleshooting Failed Requests Using Tracing in IIS 7.0 http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis-70/.

-=Oleg=-

Tuesday, July 14, 2009

Silverlight Styling

Changing the styling of the Silverlight controls is simple. It’s somewhat similar to CSS, but it's more robust and syntax is completely different. What is different in Silverlight and WPF is that you can completely re-define control’s UI and behavior using styles. It took me about 20 minutes from absolute zero to the “Aha!” moment and become an expert in styling WPF and Silverlight applications. Here are the 3 links that helped me to clear the mistery behind Silverlight styles:


1.       Using Style Elements to Better Encapsulate Look and Feel – a good example of how to change control’s properties using styles


2.       Using Control Templates to Customize a Control's Look and Feel – a step further that shows how to make control look anyway you want. In other words how to draw control’s UI from scratch or combine several controls into one. All using styles! Pretty amazing yet simple.


3.       MSDN: Customizing the Appearance of an Existing Control by Using a ControlTemplate – the final piece of puzzle is about how to make control to react on events like Pressed or Disabled and change its appearance. Just few more words about this. Basically every control has a list of pre-defined events (they called states in Silverlight) which can be referenced by ControlTemplate. The list of states differs for each control. This information is available in MSDN on control’s Class page as a list of TemplateVisualStateAttribute attributes applied to the class.


-=Oleg=-

Friday, July 10, 2009

Silverlight 3 has been released

Long awaited Silverlight 3 has been released. Here is the download link:

http://www.microsoft.com/silverlight/get-started/install/default.aspx

New features:
  • Media: New codec support (H.264, AAC, MPEG-4), raw bitstream Audio/Video API, and improved logging for media analytics

  • Graphics: GPU Acceleration and hardware compositing, perspective 3D, bitmap and pixel API, pixel shader effects, and Deep Zoom improvements

  • SEO: Deep linking

  • Application development: multi-touch support, 60+ controls available, and library caching support

  • Data: Data-binding improvements, validation error templates, server data push improvements, binary XML networking support, and multi-tier REST data support

  • -=Oleg=-

    Tuesday, June 30, 2009

    How to serialize / deserialize ANY object using XmlSerializer

    There is a lot to say about object serialization. I just want to cover the gray area when you need to serialize object which has references to other objects, but references are not strongly typed. For example, if you have your classes structured like that:

        public class MainClass


        {


            public object Data { get; set; }


        }


        public class ChildClass1


        {


            //some properties


        }


        public class ChildClass2


        {


            //some properties


        }


     


    where Child Classes can be assigned to Data property of the MainClass and if you construct XmlSerializer object like this


    new XmlSerializer(typeof(MainClass));


    Then both serialization and deserialization will fail throwing an error saying that it has no knowledge of ChildClass1 or ChildClass2 classes. To resolve this error you need to provide XmlSerializer with additional class types which serializer may meet on its way when parsing XML string. Here is how to do that:


    new XmlSerializer(typeof(MainClass), new Type[] { typeof(ChildClass1), typeof(ChildClass2) });


    Here is the set of functions I use to serialize / deserialize my objects:


            public static string SerializeToString(object aObject)


            {


                return SerializeToString(aObject, null);


            }


     


            public static string SerializeToString(object aObject, Type[] extraTypes)


            {


     


                XmlSerializer aSerializer;


                if (extraTypes == null)


                    aSerializer = new XmlSerializer(aObject.GetType());


                else


                    aSerializer = new XmlSerializer(aObject.GetType(), extraTypes);


                MemoryStream aMemoryStream = new MemoryStream();


                StreamReader aStreamReader = new StreamReader(aMemoryStream);


     


                XmlWriterSettings aXMLWriterSettings = new XmlWriterSettings();


                aXMLWriterSettings.Encoding = new UTF8Encoding(false);


                aXMLWriterSettings.ConformanceLevel = ConformanceLevel.Document;


                XmlWriter aXMLWriter = XmlWriter.Create(aMemoryStream, aXMLWriterSettings);


     


                aSerializer.Serialize(aXMLWriter, aObject);


                aXMLWriter.Flush();


                aXMLWriter.Close();


                aMemoryStream.Position = 0;


                return aStreamReader.ReadToEnd();


            }


     


     


            public static object DeserializeFromString(string aMessage, System.Type aType)


            {


                return DeserializeFromString(aMessage, aType, null);


            }


     


            public static object DeserializeFromString(string aMessage, System.Type aType, Type[] extraTypes)


            {


                XmlSerializer aXMLSerializer;


                if (extraTypes == null)


                    aXMLSerializer = new XmlSerializer(aType);


                else


                    aXMLSerializer = new XmlSerializer(aType, extraTypes);


                System.IO.StringReader aStringReader = new StringReader(aMessage);


     


                return aXMLSerializer.Deserialize(aStringReader);


            }


     


    -= Oleg =-