Saturday, May 26, 2012

This is Limited

A Secret to Creative Problem Solving - http://pulse.me/s/9wSe4

Thursday, March 1, 2012

Brain Teaser 7

Measure the time. Assume you do not have any other means to measure time but the two provided hourglasses. One hourglass exactly measures 4 minutes and other hourglass exactly measures 7 minutes.

How would you exactly measure 9 minutes using the above two hourglasses?

Brain Teaser 6

You have a gold bar as payment for an employee. This gold bar is the payment for 7 days of work for the employee. You have to pay the employee everyday. If you pay the entire gold bar then employee will take it and not show up for the remaining days. You are required to pay the employee at the end of the day.

You are allowed to split the bar into smaller pieces. It costs money to split the bar so lesser the number of splits the better it is for you.

How many pieces / slices you will make of the gold bar to make sure you can make the daily payments and also keep the employee for all 7 days.

Thursday, February 2, 2012

Brain Teaser 5...

How many times would you weight...

Have you seen those ball bearings used in lot of places, cars for that matter? These small shiny balls may look the same but they differ in weight, density etc. Well the puzzle in not about figuring out what type of ball bearing it is. Here is the classic quality test but then you do not have all the latest tools. You have a weighing balance (the one with two bases).
There are 15 balls that look exactly the same. You cannot make out any difference but one of them is heavier. How many time(s) would you have to use this balance to find out the heavy one? Now off course it will be best to use the balance for least number of times. I will tell you why that is....once you answer this.

More coming up....


Now if there were 23 balls instead of 15 and the first measure costs $10, second costs $100, third costs $1000 and 4th onward each measure costs $10. What will be your approach?

Amazing video

I found this on YouTube. Phenomenal video. Take a look

Sunday, January 22, 2012

Limitless - NZT

Have you watched the 2011 thriller movie - "Limitless", it has a very interesting plot. I was really amazed at what was shown. Take a look, if you have Netflix it is available on there.


It has a very interesting topic and too my amazement look at his web site. http://theclearpill.com/
Watch the movie and then the web site would interesting.


What do you think?

Brain Teaser 4 ...really!

Software developers are different...

The other day I was thinking we software engineers can solve a lot of problems. We have a sharp mind (definitely like to talk about that). I thought how many software engineers will it take to change a light bulb?


What do you think?

Did you know that 100% of Software professionals wish they had a choice other than computers in their life at least once in their lifetime 

Friday, December 16, 2011

Brain teaser series 3...


Find the right candy jar...
Who does not love candy? I always loved those colorful candies but I liked that one colored candy. Now I got red candy and blue candy but I like to get the red one, here is my trouble. There are 3 jars (not transparent) that are mislabeled, one jar has red candy, one has blue candy and one has a mix. Now the mix is not necessarily 50-50, it could be any ratio. I have to blindly pick candy from the jars and find out which jar has which type of candy in the minimal possible turns. How many turns are needed to find out which Jar has what candy?

Did you know that red jelly beans are kid's favorite. Have fun :)

Thursday, December 15, 2011

Brain teaser series 2...

Flip the coin...
I always loved those coin tricks and wondered how it happened. While making the coin magically disappear is definitely a mind trick (will talk about that too) but the coin flipping is mathematical. Here is an easy one, I flipped two quarter-coins and immediately announced that one came out as head. What is the chance that the second coin will also be a head?


If you were in Las Vegas would you bet on head or tail for the second coin? Have fun :)

Monday, November 28, 2011

Brain teaser series 1...

Run for your life...
Mr. Joy enjoys some risk and likes to explore the nearby area. In the beautiful surrounding there is a train track that goes through a mysterious tunnel. One fine morning Mr. Joy decided to take a walk through the tunnel. While Mr. Joy was 1/4 way on the tunnel, he hears the train whistle. A quick thinker Mr. Joy calculates that if he runs back he would just make it out of the tunnel before train gets in the tunnel and if he runs forward he will just make it out of the tunnel before train hits him. While Mr. Joy saved his life, he left you with a problem, how fast was this train travelling compare to Mr. Joy?

This is old school physics problem with all basic assumptions for this kind of puzzle. Assume Mr. Joy can run with same speed in both direction. He can accelerate to his top speed right away. Train barely misses him if he would run in either direction

Looking forward to see some solution(s)

Sunday, November 27, 2011

Business Intelligence


What is business Intelligence
I am sure a lot of people can define business intelligence but what we need to know is how it applies to us our business, our life and things we do. Over the last few decades, we have collected data and we probably have overwhelming data about a person, from financial records to personal email, phone records etc. While this information is useful for your own records it provides a vast scope for someone in the field of offering services or goods a great opportunity to find out what they can launch or produce. 

While this is a short example and a survey could do that but have you ever thought of magic. While magical tricks (are tricks) and some are really sophisticated, business intelligence is the magic for this data. Data is any piece entered into a system but when we interpret it, it becomes information. When this goes beyond a regular interpretation, business intelligence comes into play. 

Have you ever thought about this if the person entering next in the car dealership will buy the car or not? Well, if you are into sales there, you know the other brain tricks (that I will talk about in another topic) but you wish you knew so you could spend your time appropriately. Well based on the vast data that we have, a simple survey may be a tool that could give you the answer with pretty high confidence. For example, how many car this person already own, is he / she a house owner? how many children? etc.

Business intelligence is not about what we can see but what we cannot see. With that said, here is my introduction to BI. 

Would love to get some feedback and comments...

Saturday, July 16, 2011

How to live life?

Live for today and enjoy what you have or plan for Tomorrow?


Overcome your fear. This is one place where Earth is the limit ;)
If you can do this then you can fly through all problems :)


Ride the ocean but don't be foolish. Enjoy, today is the day and time to enjoy

One day I would like to be in the driver seat there. Believe me you would know that perfection is not achieved but is a practice.


I have ridden in the roughs with my bicycle. It was always thrilling to be on the top

Don't need a pilot :)

Monday, December 27, 2010

Add / Subtracting days from a date to get the next date without counting weekend

Recently had a situation where I had to calculate the next date based on the duration provided to the function. The catch was not to count the weekend (Saturday and Sunday) in the calculation.

I did a lot of google search and landed with  a way to get the next date if the duration was positive (that is the next date will be later than the provided date). I needed a way to go back as well.

After a lot of learning, I came up with this T SQL function for SQL Server that will allow you pass a positive or negative duration parameter and a date. Based on the parameter, it will add or subtract numbers.

Here is the T SQL function. Have fun and enjoy. Feel free to use this, I would really appreciate acknowledgement and link to my blog (http://dmknol.blogspot.com/)

create function [dbo].[GetEndDate_ByWeekdays]
(
 @pdtStartDate datetime,
 @piDuration int
)
returns datetime
as
begin
 declare @rdt datetime
 -- calculating forward
 if (@piDuration > 0)
 begin
   select @rdt = dateadd (d, case datepart (dw, @pdtStartDate) when 7 then 2 when 1 then 1 else 0 end, @pdtStartDate)
   + (datepart (dw, dateadd (d, case datepart (dw, @pdtStartDate) when 7 then 2 when 1 then 1 else 0 end,
    @pdtStartDate)) - 2 + @piDuration) % 5
   + ((datepart (dw, dateadd (d, case datepart (dw, @pdtStartDate) when 7 then 2 when 1 then 1 else 0 end,
    @pdtStartDate)) - 2 + @piDuration) / 5) * 7
   - (datepart (dw, dateadd (d, case datepart (dw, @pdtStartDate) when 7 then 2 when 1 then 1 else 0 end,
   @pdtStartDate)) - 2)
 end

 -- calculating backward
 else
 begin
  -- local variable
  declare @liDuration int,
    @ldt_orgStart datetime,
    @li_orgDuration int
   
  -- save original value
  set @ldt_orgStart = @pdtStartDate
  set @li_orgDuration = @piDuration
  -- divide the duration into set of fives
  while abs(@piDuration)/5 > 0
   begin
    set @piDuration = @piDuration + 5
    --select [@piduration] = @piDuration
    set @liDuration = 7 - 2*(datepart (dw, @pdtStartDate) /7) + (datepart (dw, @pdtStartDate) -2)/7
    set @liduration = @liDuration *(-1)
    --select [@liduration] = @liDuration
    set @pdtStartDate = dateadd(d, @liDuration, @pdtStartDate)
    --select [@pdtStartDate_inside] = @pdtStartDate
   end
  -- add days that were not covered within the five sets
  if (abs(@li_orgDuration) % 5 > 0)
  begin
   --select @piDuration, @pdtStartDate, datepart (dw, @pdtStartDate)
   set @liDuration = case when datepart (dw, @pdtStartDate) <= abs(@piDuration) + 1 then abs(@piDuration) + 2
         when datepart (dw, @pdtStartDate) = 1 then abs(@piDuration) + 1
         else abs(@piDuration) end
   set @liDuration = @liDuration * (-1)
   --select [@liDuration_last] = @liDuration
   set @rdt = dateadd(d, @liDuration, @pdtStartDate)
  end
  else
   set @rdt = @pdtStartDate
 end

 -- return the date
 return @rdt
end
GO

Saturday, October 30, 2010

TSQL Averages with Rollup

Here is tsql way of getting averages and also rolling up. Below example is using adventureworks database that is available with SQL server 2008. It is getting average pay rate by each department and also overall by the company.

use [AdventureWorks]
select[Department] = case when grouping(d.GroupName) = 1 then 'Company Average'
                              else d.GroupName end,
            [Average Pay Rate] = avg(p.Rate)
from (select [EmployeeID], [Rate] = max([Rate])
            from [HumanResources].[EmployeePayHistory]
            group by [EmployeeID]) p
      inner join [HumanResources].[EmployeeDepartmentHistory] h
                  on h.[EmployeeID] = p.[EmployeeID] and h.[EndDate] is null
      inner join [HumanResources].[Department] d on d.[DepartmentID] = h.[DepartmentID]
group by d.[GroupName]
with rollup
order by 1


Recently one of the buzz word in the technology world was "Lean"

I decided to find it little more about it. A new term has been coined, Lean software development. Well the work and definition below is from various sites and sources on internet. I would like to thank them and not claim this is my work. This is to insitgate discussion and blog the very purpose of having this site.

Lot of you may know about Sixsigma, this is kind of an extension, here is what I found. Looking forward to get some feedback.

Lean software development is a translation of lean manufacturing principles and practices to the software development domain. Adapted from the Toyota Production System, a pro-lean subculture is emerging from within the agile community.
Eliminate waste
  • unnecessary code and functionality
  • delay in the software development process
  • unclear requirements
  • bureaucracy
  • slow internal communication
Amplify learning
Software development is a continuous learning process with the additional challenge of development teams and end product sizes. The best approach for improving a software development environment is to amplify learning. The accumulation of defects should be prevented by running tests as soon as the code is written. Instead of adding more documentation or detailed planning, different ideas could be tried by writing code and building. The process of user requirements gathering could be simplified by presenting screens to the end-users and getting their input.
The learning process is sped up by usage of short iteration cycles – each one coupled with refactoring and integration testing. Increasing feedback via short feedback sessions with Customers helps when determining the current phase of development and adjusting efforts for future improvements. During those short sessions both Customer representatives and the development team learn more about the domain problem and figure out possible solutions for further development
Decide as late as possible
As software development is always associated with some uncertainty, better results should be achieved with an options-based approach, delaying decisions as much as possible until they can be made based on facts and not on uncertain assumptions and predictions. The more complex a system is, the more capacity for change should be built into it, thus enabling the delay of important and crucial commitments.
An agile software development approach can move the building of options earlier for customers, thus delaying certain crucial decisions until Customers have realized their needs better. This also allows later adaptation to changes and the prevention of costly earlier technology-bounded decisions. This does not mean that no planning should be involved – on the contrary, planning activities should be concentrated on the different options and adapting to the current situation, as well as clarifying confusing situations by establishing patterns for rapid action.

Deliver as fast as possible
In the era of rapid technology evolution, it is not the biggest that survives, but the fastest. The sooner the end product is delivered without considerable defect, the sooner feedback can be received, and incorporated into the next iteration. The shorter the iterations, the better the learning and communication within the team. Without speed, decisions cannot be delayed. Speed assures the fulfilling of the Customer's present needs and not what they required yesterday. This gives them the opportunity to delay making up their minds about what they really require until they gain better knowledge. Customers value rapid delivery of a quality product.
The Just-in-Time production ideology could be applied to software development, recognizing its specific requirements and environment. This is achieved by presenting the needed result and letting the team organize itself and divide the tasks for accomplishing the needed result for a specific iteration. At the beginning, the Customer provides the needed input. This could be simply presented in small cards or stories – the developers estimate the time needed for the implementation of each card.
Empower the team
There has been a traditional belief in most businesses about the decision-making in the organization – the managers tell the workers how to do their own job. In a Work-Out technique, the roles are turned – the managers are taught how to listen to the developers, so they can explain better what actions might be taken, as well as provide suggestions for improvements. Most experienced project managers have simply stated the key for a successful project – "Find good people and let them do their own job."
Another mistaken belief has been the consideration of people as resources. People might be resources from the point of view of a statistical data sheet, but in software development, as well as any organizational business, people do need something more than just the list of tasks and the assurance that they will not be disturbed during the completion of the tasks. People need motivation and a higher purpose to work for – purpose within the reachable reality, with the assurance that the team might choose its own commitments. The developers should be given access to Customer; the team leader should provide support and help in difficult situations, as well as make sure that skepticism does not ruin the team’s spirit.
Build integrity in
The Customer needs to have an overall experience of the System – this is the so called perceived integrity: how it is being advertised, delivered, deployed, accessed, how intuitive its use is, price and how well it solves problems.
Conceptual integrity means that the system’s separate components work well together as a whole with balance between flexibility, maintainability, efficiency, and responsiveness. This could be achieved by understanding the problem domain and solving it at the same time, not sequentially. The needed information is received in small batch pieces – not in one vast chunk with preferable face-to-face communication and not any written documentation. The information flow should be constant in both directions – from Customer to developers and back, thus avoiding the large stressful amount of information after long development in isolation.
Automated tests are also considered part of the production process, and therefore if they do not add value they should be considered waste. Automated testing should not be a goal, but rather a means to an end, specifically the reduction of defects.
See the whole
Software systems nowadays are not simply the sum of their parts, but also the product of their interactions. Defects in software tend to accumulate during the development process – by decomposing the big tasks into smaller tasks, and by standardizing different stages of development, the root causes of defects should be found and eliminated. The larger the system, the more organizations that are involved in its development and the more parts are developed by different teams, the greater the importance of having well defined relationships between different vendors, in order to produce a system with smoothly interacting components. During a longer period of development, a stronger sub- contractor network is far more beneficial than short-term profit optimizing, which does not enable win-win relationships.
Lean thinking has to be understood well by all members of a project, before implementing in a concrete, real-life situation. “Think big, act small, fail fast; learn rapidly” – these slogans summarize the importance of understanding the field and the suitability of implementing lean principles along the whole software development process.

SQL server split received string using XML

Several time, we have a need to split the string based on a delimiter, for instance to handle multiple input filter parameters etc.
 
Most of the time we end up using a user defined function that accepts a string and a delimiter and returns a table of split values. Function may be in-efficient at times.
 
Here is an XML way to split the input string and get a result within a table
 
declare @xml as xml,@str as varchar(100),@delimiter as varchar(10)set @str='A,B,C,D,E'set @delimiter =','set @xml = cast(('<X>' + replace(@str, @delimiter, '</X><X>') + '</X>') as xml)select N.value('.', 'varchar(10)') as value from @xml.nodes('X') as T(N)

Need to get details on a folder with sizes, create a clean excel sheet

' PLEASE NOTE THAT YOU WOULD NEED EXCEL INSTALLED ON YOUR MACHINE
 
Dim oFS, oFolder
Dim objexcel, r, lnameArray, lname, nameLength
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFolder = oFS.GetFolder("D:\GE")
Set objExcel = createobject("Excel.application")  
objexcel.Workbooks.add
objexcel.Cells(1, 1).Value = "Folder Path"
objexcel.Cells(1, 2).Value = "Folder Name"
objexcel.Cells(1, 3).Value = "Size (MB)"
objexcel.Cells(1, 4).Value = "# Files"
objexcel.Cells(1, 5).Value = "# Sub Folders"
objexcel.Visible = True
Wscript.Sleep 300
r=2

ShowFolderDetails oFolder, r
   
   
'    objexcel.ActiveWorkbook.SaveAs("LogonReport.xls")
'    objexcel.Quit
MsgBox "Done"   
   
Function ShowFolderDetails(oF,r)
    Dim F
    objexcel.Cells(r, 1).Value = oF.Path
    objexcel.Cells(r, 2).Value = oF.Name
    objexcel.Cells(r, 3).Value = oF.Size /1024\1024
    objexcel.Cells(r, 4).Value =  oF.Files.Count
    objexcel.Cells(r, 5).Value =  oF.Subfolders.count
    r = r+1
    for each F in oF.subfolders
        ShowFolderDetails F, r
    next
End Function

SQL Server - Insert in identity column for a table

Sometimes there is a need to insert data into a table that has identity column. Example when you would like to restore a table from a backup including the same IDs so integrity is maintained. Here is simple script

--set identity insert on
set identity_insert <table_name> on

--set identity insert off
set identity_insert <table_name> off