Showing posts from January, 2013

Android getOrientation()

  I spend some time today trying to understand getOrientation()  and found a few notes when I googled, but most of the notes left things fuzzier than needed. The author’s appear to know what they were talking about – but failed to express it with a good clarity…   The documentation states:   getOrientation (float[] R, float[] values) Computes the device's orientation based on the rotation matrix.   Not exactly a rich description! When I attempted to write code, the expected results did not occur….   The core of the code is: SensorManager.getRotationMatrix( rotationMatrix , null , accelVals , magVals ); SensorManager.getOrientation( rotationMatrix , orientationVals ); textView1 .setText( " 0:" + orientationVals [0]+ " 1:" + orientationVals [1]+ " 2:" + orientationVals [2]); Where the values are supplied by (I’ve omitted the code for stabilizing the values) @Override public void onSensorChanged(SensorEvent se) {

Interview: A question from when I did CS 101…

Look at the following code: static int OpPerf_0( int x, int y, int z) { return x + y + z; } static int OpPerf_1( int x, int y, int z) { return sum(x,sum(y,z)); } static int sum( int x, int y) { return x + y; } First estimate the difference of performance between OpPerf_0 and OpPerf_1? Write out pseudo-machine code on what will be executed with OpPerf_0 and OpPerf_1.   This is a C#, Java, C++, neutral question that tests the person’s understanding of what actually happens when code is executed.   OpPerf_0 LOADADDR OpPerf_O PUSH ReturnAddress PUSH X PUSH Y PUSH Z CALL  LoadAddress POP X POP Y POP Z MOVE X, ACC-1 MOVE Y, ACC-0 ADD MOVE Z, ACC-1 ADD PUSH ACC-1 CALL ReturnAddress   I will leave OpPerf_1 to the reader….   OpPerf_1 LOADADDR OpPerf_1 PUSH ReturnAddress PUSH X PUSH Y PUSH Z CALL LoadAddress POP X POP Y POP Z

Interview: Find Kth Largest in two arrays of ordered integers

This one is actually an improvement over the usual proforma CS-101 questions. A possible solution is below One of the key item is whether the answerer address boundary conditions (which is half the solution!)   public int FindKthLargest( int [] list1, int [] list2, int kth) { if ((list1 == null && list2.Length < kth) || (list2 == null && list1.Length < kth) || (list1 != null && list2 != null && (list1.Length + list2.Length) < kth)) { throw new ArgumentException ( "Lists are too short" ); } if (list1 == null ) { return list2[list2.Length - kth]; } if (list2 == null ) { return list1[list1.Length - kth]; } int pt1 = list1.Length - 1; int pt2 = list2.Length - 1; int maxValue = (list1[pt1] > list2[pt2]

Interview: Find the Number that repeats the most times in a row in an array of integers

This is another one of these not related to job functions questions that get asked. The solution is simple: public static int MaxRepeatInArray( int [] arr) { //Input checks if (arr == null || arr.Length < 1) { throw new DataException ( "Empty Array" ); } int bestChoice = arr[0]; int bestCounter = 1; int currentChoice = arr[0]; int currentCounter = 1; for ( int i = 0; i < arr.Length; ++i) { if (currentChoice == arr[i]) { currentCounter++; } else { if (currentCounter > bestCounter) { bestChoice = currentChoice; bestCounter = currentCounter; } currentChoice = arr[i]; currentCounter = 1; } } // Incase sequence is at end if (currentCounter > bestCounter) { bestChoice = currentChoice; bestCounter = currentCounter;

Interview: Efficiently implement x^y for positive integers using basic operators.

There are three solutions that come to mind.. public static int PowerOfY_0( int x, int y) { int result = 1; for ( int i = 0; i < y; i++) result *= x; return result; } The second solution is a bit of fun, because you are not using the power function but other math functions. Definitely efficient in terms of lines of code.   public static int PowerOfY_1( int x, int y) { return ( int ) Math .Round( Math .Exp(y* Math .Log(x, Math .E))); } The expected function is something like this: public static int PowerOfY( int x, int y) { int result = 1; while (y > 0) { if (y % 2 == 1) result *= x; y = y / 2; x *= x; } return result; } Of course, this is a bad question – you are really testing if the person can remember prior canned solutions and not their ability to think.  IMHO, the interviewer asking the question is suspect on their ability to think. It has no relation

Removing SYSPRO Business Object Dependencies

Summary Recently I was assigned the task of removing all dependencies on SYSPRO business objects inside an Asp.Net 2.0 application. These are the steps to find underlying SQL calls made by the business objects.    SYSPRO Business Objects SYSPRO Business objects are contained in the Interop.Encore.dll. The returned result is XML for the calls I dealt with.   The data items were, eventually, pulled out of the XML and used as single data points or as lists. You may choose to return XML from the new SQL calls you write.  This allows you to plug in the results and leave the rest of the legacy code.   Since the purpose of my task was to find any and all speed improvements, I removed the XML and dealt directly with SQL results. This required more data layer build-up but the benefit, beyond speed, was that I learned exactly what data was required and how it was ultimately used since I had to reverse engineer all the way to the level of usage.      The most interesting p

Cascading Dropdown Boxes with Data coming from XML

A friend from my days at Blackboard sent me the following code mockup and asked me how to make it work. < asp : Content ID ="BodyContent" runat ="server" ContentPlaceHolderID ="MainContent"> < asp : XmlDataSource ID ="XmlDataSource1" DataFile ="FeatureRequestDatasource.xml" runat ="server" XPath ="product/feature" ></ asp : XmlDataSource > < asp : XmlDataSource ID ="XmlDataSource2" DataFile ="FeatureRequestDatasource.xml" runat ="server" XPath ="product/feature/area"></ asp : XmlDataSource > < asp : XmlDataSource ID ="XmlDataSource3" DataFile ="FeatureRequestDatasource.xml" runat ="server" ></ asp : XmlDataSource > < h3 > Sample Feedback Submit Form </ h3 > < div > Product Feature < asp : DropDownList ID ="DropDownList1" DataSourceID =&quo

Interview Question: What are Wait Stats in SQL Server?

This should required only a short answer, such as “It provides statistics on what SQL Server is waiting for. For example, there is a Stat for Logging (LOGBUFFER, LOGMGR_QUEUE). One of the most important ones is the wait time for writing to media (WRITELOG).” Asking for the precise name is a bit unfair – such a question would be testing rote/memory abilities and not understand of what is going on. Some more important names are IO_COMPLETION, SOS_SCHEDULER_YIELD, PAGELATCH_XX, PAGEIOLATCH_XX, etc.   You could ask about general types, for example: Resource Waits (i.e. internal resources), External Waits and Queue Waits. However, a poor response may easily occur if the question is not very carefully phrased --   However, asking what you would do to resolve a high WRITELOG or LOGBUFFER statistics is a much better question. The typical answers could include: If you are using a virtual machine, make sure that data disks are passthru and not virtual disks Change the RAID confi

An old SQL Server Interview Question: What are Crow’s Feet?

I recall being asked that question at an interview long ago. In the circles that I had been working we had never used that (academic) term and had been using the diagramming tools in SQL Server Management Studio(SSMS). It was simply what we used. So what are crow’s feet?   It is a diagramming notation which, incidentally, is not supported in SQL Server Management Studio but is supported in third party tools. Since I had been working for Microsoft’s ITG SQL Server Team for several years prior without any third party tools --- I could not return a snappy answer. The origin of this was that the early adapters moved to Oracle, so this because an attitude issue with Microsoft.   Today, crow’s foot notation has become the non-Microsoft industry standard in stead of SSMS infinity key notation. The comical thing is that Microsoft Visio does support crow’s foot notation. A few example tools that uses this notation are: ARIS , System Architect , PowerDesigner , Toad Data Modeler , DeZig