Saturday, September 5, 2015

#codingexercise
Generate n numbers in ascending orders which are having given k factors.
For example, if we are given {2,3,4,7}
The numbers generated would be 2,3,4,6,7,8,9,10...
Let us assume that there are no duplicates in the number.

# http://www.cs.utexas.edu/users/EWD/ewd07xx/EWD792.PDF

n = 15
bases = [2, 3, 4, 7]

nums = [1] * n
candidates_indexes = [0 for _ in bases]
candidates = [base for base in bases]

for i in range(1, n):
    nextn = min(candidates)
    nums[i] = nextn

    for index, val in enumerate(candidates):
        if val == nextn:
            candidates_indexes[index] += 1
            candidates[index] = bases[index] * nums[candidates_indexes[index]]


print(nums)
Start:
candidates=[]
candidate_indexes []
nums[2]
From Stackoverflow
The original design talked about prime factors. Here we have liberally used non primes.

Friday, September 4, 2015

In continuation of the book review of The Innovative Sale by Mark Donnolo, we now review the four phase Innovative Sales Process. This uses a blend of analytical thinking and functional creativity. It consists of four phases and there are eight steps within the four phases.
Phase 1: Conditions -  This is the set of boundary conditions  such as the constraints that include the time, price or product specifications that the customer has requested.
Phase 2: Known approaches - All of the brainstorming in the sales organizations consists of this phase.
Phase 3: Discovery -  This is where innovation happens. Ironically, this is where teams start to resist because it puts them out of their comfort zones and they complain about feeling lost.
Phase 4: Application - This is where we rubber meets the road as the idea is put to practice.
Now we look at the steps within each phase. The first step of phase 1 is when we define the challenge and the constraints, confirm or validate it or improve our understanding of the broader context and give more space for ourselves to act within this boundary.
In step 2 we gather insights about the challenges in the project.  These could include
customer challenges - in terms of financial performance, markets, products and resources,
causes - This set of questions addresses the causes and drivers behind the customer challenge.
precedents - when we lookup previous business models
In step 3 we create initial approaches - by looking up a list of all that has worked before in similar situations and picking out candidates. This just helps with a quick answer to the challenge and may not be the one that we find as we progress into the next few steps.
In step 4 we destroy false constraints by testing the boundaries which include operating rules, procedural rules and the accepted truths. This is where the discovery phase begins and we try to find alternatives or compromises to that constraints.
In step 5 we combine parallels which many not even come from business but from other life situations. In order to do that, we
look into the generations - the term generations here means looking beyond the immediate environment, company, competitors, industry or business. Parallels in each of these generations provide solutions that may never have been considered.
deconstruct our challenge question - we have an inventory of possible parallels from the five generations which we use together with the parts of the question for mix and match
find matches that address twenty five percent of the challenge -  because we use the rest to change our thinking
and put the pieces together - ideas generated by examining parallels and put them together to test their logic and potential application.
In step 6, we explore horizontally, where we create an abundance of ideas across a divergent range of options
In step 7 we develop vertically, which entails selecting the best ideas and digging deep down to build out the solution
The final step is to implement and communicate  which requires managing change. Here we :
understand the degrees of change where each degree represents a risk and a communications opportunity
we develop our positioning - where we recapture our reasoning and position our overall thinking
we operate our communications campaign - where we bring together target audiences, directed messages, communication medium, proof sources and message repetition on schedule
we manage resistance and push through - here we find where we can be flexible and where we cannot for a successful outcome.
#codingexercise
string x = "1..5,8,11..14,18,20,26..29"
string y = "1,2,3,4,5,8,11,12,13,14,18,20,26,27,28,29"
Expand a given string x to y.
For every numeral in x if the following notation is .., then we take the next numeral as end of range and expand it. If the range notation is missing, we copy it.
Let us take a closer look at some of the test cases.
For example, the range could start with the marker or the end numeral for the range may be missing.



Thursday, September 3, 2015


This is a book review of the innovative sale by Mark Donnolo.

Sales and creativity expert Mark Donnolo introduces us to blending the left-brain and right-brain thinking in order to develop better answers for your customers or market that differentiate you from the competition. The reason for the blend is that most people tend to operate in one of two extremes – operating analytically or by the seats of their pants. He argues this is a proven sales innovation breakthrough.

Mark starts by challenging the notions around creativity. He reminds us of a few perception and realties. For example, there is a perception that you have to be born with creativity. The reality is that most creators and innovators have learned how to be creative. Another perception is that creative ideas come from eureka moments. The reality is that creative moments are usually the culmination of a creative problem solving progression. Similarly another perception is that you have to work in a heralded innovative organization in order to be creative while the reality is that any organization can adopt innovative practices, and any individual can use creative methods independently. One more perception is that innovation doesn’t apply to sales while the reality is that innovation wins deals. Yet another perception is that creativity is creativity and it’s all the same whereas the all creativity is not created equal.

Mark cautions against what he means by creativity. He says artistic creativity has limited application in sales which is governed more by goals, expectations and objectivity. Instead, sales organizations demand functional creativity where there is a right answer.

He says the first step is to recognize that there are constraints. Constraints enable creativity. For example, a sales strategy for your CRM product only comes into picture when your customer has a tight budget, a three month time frame and must get approval from the CFO.

Innovative ideas for such strategy require the best of both brains. Finding equilibrium is necessary.

There are six innovative sales principles – inspired by principles of art and each one has three imperatives.

The first principle is Pattern. In sales, pattern refers to our instinct to find related ideas in a given situation. To apply this principle, use the following imperatives:

1)      Get comfortable with feeling lost.

2)      Combine unrelated ideas

3)      Become a student of history

The second principle is Variety. Variety describes the dissimilarities between design and the same idea applies to innovative thinking. The three imperatives in this case are:

1)      Produce an abundance of ideas

2)      Think in divergent directions

3)      Know that less is more

The third principle is Unity. Unity refers to how all of the elements work together to make a whole. The three imperatives in this case are:

1)      Assemble the right team

2)      Collaborate as an individual

3)      Understand other perspectives

The fourth principle is contrast. Contrast invites the sales team to critically question and pushback against established practices. The three imperatives in this case are:

1)      Break rules

2)      Don’t accept the accepted

3)      Get comfortable with criticism

The fifth principle is movement.  Movement refers to the natural progression of ideas as we proceed through the problem-solving process. The three imperatives in this case are :

1)      Ask the right questions

2)      Grow with the flow

3)      Walk away from the problem

The sixth principle is harmony. Harmony is achieved when there are several different but related elements in a composition. The three imperatives in this case are:

1)      Keep perspective

2)      Check degrees of change

3)      And be persistent.

 

Wednesday, September 2, 2015

In continuation of the review of the book titled Rookie Smarts by Liz Wiseman, we look at a few more instances where constant learning is more valuable than mastery and how to apply this principle. 
The author invites us to take a look at what it takes to rouse us from the comforts of the convention. She says one such thing is the newer challenge level that  we should overcome by working up the learning curve. In some places, where we start working our intellectual muscles again, we feel the most engaged. 
She says don’t hesitate to place yourself on new terrains but pace yourself.  
Shift from leader to learner. She says in this case you have to overcome the confirmation bias to capture the tendency of the people to favor information that support their hypotheses. There is also the convenience factor playing in this as we move from  where we are to where we want to be. 
We should step into the discomfort zone. Its only outside the comfort zone where we encounter “expectation failure” – when things don’t go as we want. 
But we pace ourselves by taking small steps – when the gap is too big, we break. Perpetual rookies must continuously guard against routines. 
The rookie smarts not only apply at a personal level but also at an organizational level. Rookies are most capable than most people imagine. But they need managers who can place them in an environment conducive to learning and insight. There are three ways how this can be done: 
  1. Freedom with direction: as a manager, provide clear directions, guardrails and criteria for completeness of solution. But direct them to experts. Activate the Hunter-gatherer mode. 
  1. A constructive challenge: Offer stretch goals, but don’t overwhelm the rookies. Provide challenges with feedback. Just as the challenges should be small, the best feedback comes in small doses and quick bursts. 
  1. A tightrope with safety net: The author says that when we operate at a level that demands more than the current skill, we walk a tight rope. As mangers make it safe for the rookie, they lower the rope and raise the safety net. 
Similar to how we build an organization with rookie smarts, we can also build powerful teams. Rookies are capable of doing amazing work themselves and they can be tapped into four configurations that have the potential to produce stellar results. 
  1. The ground and the spark : A veteran – rookie pair where the veteran brings the a ground to reality and the rookie brings energy and determination. 
  1. The talent scout and the new talent -  The rookie brings the novel ideas and a new approach and the veterans champion the rookies promise 
  1. The advisor and the entrepreneur – The rookie brings a new idea and the veteran brings contacts and network 
  1. A hetero genius team – people with different backgrounds and experience level may find it difficult to work together but it produces better outcomes where creative thinking is needed. 
The author concludes with a note on talent management. She says, when hiring, hire for traits shared by perpetual rookie. When designing a job and planning a succession, rotate talent to keep it fresh. When making development investments,  target people in rookie assignments. Finally, she reminds us that rookie smarts is not about age or experience level but a state of mind that is willing to unlearn and relearn. It is also a choice that will enable your success in the new world of changes. 
#codingexercise
Given an array of positive integers, you have to insert one of +,-*/ between two number such that the result is maximum
Since the operations are symmetric, we can sort the numbers.
For all ones we can do a sum pairwise and then multiply.
For numbers that are not ones, we can multiply them directly.

Tuesday, September 1, 2015

Authentication and Authorization modules that don’t encapsulate the credentials in one piece such as a token suffer from the problem that they are just about as secure as SMTP. Anyone can spoof anyone by passing different user ids. That said there is a real need to be able to switch users in the request.user such that an API implementation can be tested and have very little or no instrumentation for the live usage by a logged in user as well as for the passive testing for coverage. The latter can possibly be alleviated with test accounts that are created beforehand for all API implementations. Such a test account may need to be registered in the Active Directory as a user that can sign in. This may or may not be available. On the other hand, when  user information in the passed credentials are hardened, then they become tamper proof and push the switching to using different tokens.
With the above two requirements in a landscape with a typical portal or WebUI accessing different API functionalities through a gateway, we now look at the minimal steps or changes required to merely use the token and nothing else for authentication providing a one-point maintenance and hence secure switching. Each request is therefore authenticated and the sessions is guaranteed for the lifetime of the token.
Django-oauth-toolkit 0.9.0 package https://pypi.python.org/pypi/django-oauth-toolkit provides all the implementations for an RFC compliant OAuth server. By definition of OAuth, when users accept certain applications to access some or all of their information, they enable the OAuth server to cut tokens that represent the user+client+the-issuing-authority. The token can then be passed directly in the Authorization header or in its own custom header or as query string whichever is convenient.  The application can be a web portal and will have its own client id and client secret. When a user logs in to the portal, she blesses certain modules aka clients. These modules can in turn request token from an OAuth server.  Ideally, the identity provider such as Okta will implement the Oauth token server itself and hence we could use those OAuth APIs  as priority. In the absence of these OAuth apis, we write an OAuth server but don’t put it behind the Nginx server that forwards to different destinations. Since the clients are registered in  a table and the users are also registered, the OAuth server does not need to verify the requestor to issue the token. Besides, the verification of the token requestor is handled within the protocol.
The first step therefore it to use an OAuth server such as the out-of-box OAuth server with the toolkit referred above and deploy it outside the gateway to different API functionalities.
Second the portal needs to provision a page that lets clients be registered. Note that a developer who writes a client application is the user who logs in to access this page. Clients may be written by one user (owner/developer) and request the server for tokens on behalf of the users of the client. This page has captures the information such as the name, description, callback URL and environment.
Third the portal needs to provision a page that lets logged in users to permit different clients to request tokens from the OAuth server on their behalf. This page usually has the description of the client and the kind of information it will be accessing from the users profile. In addition, it may disclose all the actions it will take the user’s information.
Fourth, the use of a utility package to verify the token employs a static method (one that relies entirely on the parameters passed in and does not have an instance associated for any API implementation) that takes a request header and validates it against the OAuth server.  Given a token, an OAuth server can reverse lookup the associated user, client and check itself as the issuing authority. The method returns this looked up information.
Finally, the API implementations should have the ability to get information such as
Request.user.id
Request.user.email
Request.user.fullname
And arguably request.user.password (encrypted)

With these an API should be able to impersonate the logged in user.

Monday, August 31, 2015


We continued reviewing the book Rookie Smarts by Liz Wizeman. We read the description of the different kinds of the Rookie smart mindset which included the backpacker, the hunter-gatherer, the firewalker and the pioneer. The author notes that this does not eliminate the role played by a savvy veteran mindset. And that we could toggle between the latter and the former in unclear murky situations and changing times respectively. This she notes is the perpetual rookie mode.

Let us take a look at these mindsets in more detail.  The backpackers  are the ones who see new possibilities and explore new terrain. Like a hiker who trudes obviously past a snake lying quietly in the bush, rookies simply walk past the obstacles they don’t see and because they don’t know what they are supposed to be looking for, they can end up seeing what others fail to notice. They ask fundamental questions because they are unencumbered by rules and rituals. They see patterns and logical flaws in conventional wisdom with pattern recognition. They explore new terrain by taking shorter paths, making bigger asks, and acting erratically.  They act wholeheartedly because without reputation, rookies can operate without ego or fear of falling. They act boldly and recover quickly and they work passionately.

The hunter-gatherer emphasize the outward venturing forth, harvesting game and foraging for resources  to bring back to the tribe. They scan the environment, connect the dots and in this hunger mode, they seek out experts to teach and guide them. Seeking out experts is such a trait that if you ask a smart rookie, you get access to a team of experts. They also mobilize ideas and resources. In complex environment, winning organizations tap into the greatest number of brains. Crowdsourcing is growing as a viable and efficient alternative to in-house or expert  led solutions to complex problems.

The firewalkers demonstrate a trait that’s both cautious and quick. They see a glaring gaping hole between what they have previously done and what they must now do. They don’t necessarily lack self-confidence. The author says this rookie’s anxiety is not the clinical kind but a productive paranoia and an urge to break out of the comfort zone. Their way is to take small calculated steps by testing the waters. Since she operates in the dark, she minimizes the risk. Rookies use every available sense to navigate the way and they calibrate their movements to minimize the risks. They deliver  quickly and tend to operate in bursts.They sometimes get off track. They solve problems quickly but doesn’t mean they know which problems are the most important. They seek feedback and coaching. In fact smart managers provide continuous stream of feedback and regularly receive vital information. These rookies lack confidence but with the feedback, they translate it to intelligence.

The pioneers are the last in the different categories enumerated by the author. Their practice involves building new tools and structures because they are in a perpetual survival mode. They improvise because they didn’t have the resources or the skills they need. They work relentlessly because they lack another choice  and are motivated to push forward.

Finally the author calls out that a perpetual rookie is one who is curious, humble playful and deliberate. She takes each of these qualities into consideration as how it contributes to the rookie smarts. Some of this is straightforward but what the author shows us is that even when we are not a rookie and we exercise these traits, we see the results brought about. The rookie revival as she calls is about learning to relearn.

At a personal level, organizational level and a team level, we can utilize the rookie smarts.

int GetCount (node root)
{
If (root == null) return 0;
Int lc = GetCount (root.left);
Int rc = GetCount (root.right);
Return lc + rc +1;
}
}

Sunday, August 30, 2015


A software called Reminders:

An alarm clock and a calendar are very useful tools to remind us of a task and to execute it at the scheduled time. Its great for planning and its very personal. But the latter is what we want to change when we work on a list of resources loaned out to many people. If we had a software that could send out emails based on templates for the various resources that are currently used by others, the chore of maintenance, reuse  and reclamation becomes all the more easy. But this is just one of the usages.

A software utility like Cron is also a time-based job scheduler however in an non-interactive Unix like computer operating systems. People who setup and maintain  software environments use cron to schedule  jobs, commands or shell scripts to run periodically  at fixed times, dates,  or intervals. It’s hard for the Cron job users to use it visually in a web browser that can be accessed from a variety of devices. How then can they use it when they are not near a machine ?

Somewhere between these two extremes of a highy interactive albeit personal productivity tool to more business oriented non-interactive background job scheduler,  there is a niche space for a  software I like to call Reminders that can print labels that can be slapped on to any thing we want to remind ourselves about.

First this software can send reminders as affable to us as emails so that we have a variety of information and the context to complete the task. It involves hyperlinks and many other features. It works along the principles of a birthday alarm but provides a placeholder for a variety of reminders.

Secondly this software can send reminders not just to ourselves but to millions others. Hence its not just a little note for ourselves but one that can be our butler for informing many others. This provides the kind of white glove treatment that may set the tone for not just an event as some calendars do but for adding the kind of information that anyone and not just us can work with at their pace.

Thirdly this software can schedule any kind of job that can be exercised without intervention. Just like the commercial Cron can schedule jobs in the background, this can serve a variety of tasks.

Fourth, it prints labels that can be attached to just about anything that we want to remind us something about. Given the label, we can look up an inventory of reminders to see what the purpose and tasks are. The labels are almost nothing more than barcodes and therefore have the ability to be included in a variety of rich information.

Such is the description of the software that can be both personal, professional and efficient with fun tags or labels to attach to resources, tasks or even calendars or visiting cards to improve the productivity, reuse and value discoveries in cycles.