RSS

int.SubString() ?

How would you write a Substring function for an Integer?

 
Leave a comment

Posted by on April 16, 2015 in General

 

Tags: , ,

CAP Theorem (Consistency, Availability, Partition)

CAP theorem states that it’s impossible for a distributed computer system to have all the following simultaneously

  • Consistency
    All part of the systems see the same data.
  • Availability
    A guarantee that each request receives a response regardless of success / failure.
  • Partition tolerance
    The whole system continue to work despite disconnection, message loss or any failure in the subsystems.

Eric Brewer said that a distributed computer system can only have 2 out of these 3 functions at a time.

 
Leave a comment

Posted by on April 6, 2015 in General

 

What is HashSet Type?

  • It’s a collection, kind of like Array.
  • Store in form of object’s hash.
  • Unordered.
  • Has standard collection methods: Add, Remove, Contains.
  • Faster in term of performance, compare to List.
  • No access by index. Thus, most methods take in <T> as parameter.

Reference: MSDN

 
Leave a comment

Posted by on March 6, 2015 in General

 

Tags: ,

Bubble Sort Algorithm

A simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

bubble-sort-algorithm

Reference: Wikipedia

 
Leave a comment

Posted by on March 5, 2015 in General

 

Tags: ,

Software Laws

I was looking for a specific theorem called CAP theorem, but came across these interesting, sort of funny but somewhat true, software laws.

I think these laws are useful to get better understanding of philosophy behind a software or computer science in general.

  • Atwood’s Law

    Any software that can be written in JavaScript will eventually be written in JavaScript.

  • Brooks’s Law

    Adding manpower to a late software project makes it later.

  • Conway’s law

    Any piece of software reflects the organizational structure that produced it.

  • Miller’s law

    To understand what another person is saying, you must assume that it is true and try to imagine what it could be true of.

  • Wirth’s law

    Software gets slower faster than hardware gets faster.

 
Leave a comment

Posted by on March 1, 2015 in General

 

Tags: , , , ,

Determine Hierarchy Name Based on Inconsistent Level

Below are sets of inconsistent arrays that represents level in hierarchy:

  • [0, 1, 2]
  • [0, 1]
  • [0]

The order of hierarchy is (from the top to the bottom):

  • Director
  • Manager
  • Employee

The highest number in the array represents the bottom level in the hierarchy. The lowest number in the array represents higher level in the hierarchy.

So, given [0, 1, 2]: 0 means Director, 1 means Manager and 2 means Employee. And given [0, 1]: 0 means Manager and 1 means Employee.

What’s the most efficient way to assign LevelName property in the following data set. The answer doesn’t have to use specific programming language.

[{
    Fullname: "Bob",
    ReportTo: "",
    Level: "0",
    LevelName: ""
},{
    Fullname: "John",
    ReportTo: "Bob",
    Level: "1",
    LevelName: ""
},{
    Fullname: "Sally",
    ReportTo: "John",
    Level: "2",
    LevelName: ""
},{
    Fullname: "David",
    ReportTo: "John",
    Level: "2",
    LevelName: ""
},{
    Fullname: "Rachel",
    ReportTo: "Bob",
    Level: "1",
    LevelName: ""
},{
    Fullname: "Peter",
    ReportTo: "Rachel",
    Level: "2",
    LevelName: ""
}]
 
Leave a comment

Posted by on January 28, 2015 in General

 

Tags: , , ,

Differences Between ViewData and ViewBag in ASP.Net MVC

ViewData

  • Accessible in both controller and view.
  • Store objects as key / value pairs.
  • Introduced in ASP.Net MVC 2.
  • Use ‘magic strings’, such as:
    ViewData["stack247"] = "stack247";

ViewBag

  • Accessible in both controller and view.
  • Store objects as Dynamic type.
  • Introduced in ASP.Net MVC 3
  • Use ‘magic properties’, such as:
    ViewData.Stack247 = "stack247";

TempData

  • Accessible in both controller and view.
  • Store objects as key / value pairs.
  • Use ‘magic strings’, such as:
    TempData["stack247"] = "stack247";
  • Meant for very short-lived instance.
  • Persistent after a redirect, means TempData’s properties will still be accessible after redirection.
  • Good scenario to use is when passing error message to an error page.
  • More information: Greg Shackles’s TempData
 
Leave a comment

Posted by on January 26, 2015 in General

 

Tags: ,

 
Follow

Get every new post delivered to your Inbox.

Join 51 other followers

%d bloggers like this: