I had to help bring the country back from a recession and out of two wars and after all of that you gonna hand it over to Cinnamon Hitler.

Barack Obama interpreted by The Daily Show

It’s fine to provide guidance for beginners, but education isn’t a substitute for great app design. First and foremost, make your app intuitive. If too much guidance is needed, revisit the design of your app.

MSDN is the best documentation in the world – read the original post here.

  1. Create  helper stored procedures
USE master
GO
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
  DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
    @binvalue varbinary(256),
    @hexvalue varchar (514) OUTPUT
AS
DECLARE @charvalue varchar (514)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length)
BEGIN
  DECLARE @tempint int
  DECLARE @firstint int
  DECLARE @secondint int
  SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
  SELECT @firstint = FLOOR(@tempint/16)
  SELECT @secondint = @tempint - (@firstint*16)
  SELECT @charvalue = @charvalue +
    SUBSTRING(@hexstring, @firstint+1, 1) +
    SUBSTRING(@hexstring, @secondint+1, 1)
  SELECT @i = @i + 1
END

SELECT @hexvalue = @charvalue
GO
 
IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL
  DROP PROCEDURE sp_help_revlogin
GO
CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
DECLARE @name sysname
DECLARE @type varchar (1)
DECLARE @hasaccess int
DECLARE @denylogin int
DECLARE @is_disabled int
DECLARE @PWD_varbinary  varbinary (256)
DECLARE @PWD_string  varchar (514)
DECLARE @SID_varbinary varbinary (85)
DECLARE @SID_string varchar (514)
DECLARE @tmpstr  varchar (1024)
DECLARE @is_policy_checked varchar (3)
DECLARE @is_expiration_checked varchar (3)

DECLARE @defaultdb sysname
 
IF (@login_name IS NULL)
  DECLARE login_curs CURSOR FOR

      SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM 
sys.server_principals p LEFT JOIN sys.syslogins l
      ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa'
ELSE
  DECLARE login_curs CURSOR FOR


      SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM 
sys.server_principals p LEFT JOIN sys.syslogins l
      ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name
OPEN login_curs

FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
IF (@@fetch_status = -1)
BEGIN
  PRINT 'No login(s) found.'
  CLOSE login_curs
  DEALLOCATE login_curs
  RETURN -1
END
SET @tmpstr = '/* sp_help_revlogin script '
PRINT @tmpstr
SET @tmpstr = '** Generated ' + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
PRINT @tmpstr
PRINT ''
WHILE (@@fetch_status <> -1)
BEGIN
  IF (@@fetch_status <> -2)
  BEGIN
    PRINT ''
    SET @tmpstr = '-- Login: ' + @name
    PRINT @tmpstr
    IF (@type IN ( 'G', 'U'))
    BEGIN -- NT authenticated account/group

      SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' FROM WINDOWS WITH DEFAULT_DATABASE = [' + @defaultdb + ']'
    END
    ELSE BEGIN -- SQL Server authentication
        -- obtain password and sid
            SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary (256) )
        EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT
        EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
 
        -- obtain password policy state
        SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
        SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
 
            SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' + @PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'

        IF ( @is_policy_checked IS NOT NULL )
        BEGIN
          SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked
        END
        IF ( @is_expiration_checked IS NOT NULL )
        BEGIN
          SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked
        END
    END
    IF (@denylogin = 1)
    BEGIN -- login is denied access
      SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )
    END
    ELSE IF (@hasaccess = 0)
    BEGIN -- login exists but does not have access
      SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )
    END
    IF (@is_disabled = 1)
    BEGIN -- login is disabled
      SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'
    END
    PRINT @tmpstr
  END

  FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
   END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
GO

2. Run

EXEC sp_help_revlogin

The output is the script that creates the logins with the original Security Identifier (SID) and the original password.

G.

In a survey conducted by Microsoft among 38,000 workers in 200 countries, people spend 5.6 hours each week in meetings and 69% of survey participants considered meetings as not productive.

Yes, yes! the daily meetings from SCRUM methodology are 15 minutes long and doesn’t sum to 5.6 hours per week. But you have to consider management long meetings and mediate them with 1.25h per week SCRUM sessions. After we correlate that with 69% participants that considered meetings to be not productive will find a large bunch of SCRUM practitioners that consider those 15 minutes as wasted time.

Of course, if they do SCRUM at Microsoft.

G

M-a întrebat zilele trecute un junior de ce ar lucra într-un small business și nu ar alege un job corporatist mult mai bine plătit.

Răspunsul l-am sintetizat în tabelul următor:

Small Business Medium Business Corporate
Salariu mic așa-ș-așa mare
Ce înveți meserie scaling (aka cum să dai vina pe alții) nimic (aka best practices)
Rol de toate generalist roboțel
Influență ți se cere părerea planing primești direct planul de bătaie
Acces informații accesibile și-și ține-ți gura
Echipa îți poți alege echipa ai cît de cît o alegere ești pus unde trebuie
Autonomie just do-it indicații generale supra-control

Deși se vede clar că nu îmi place mediul corporatist, nu vreau să descurajez un job într-o firmă mare. Doar încerc să punctez compromisurile pe care trebuie să le faci pentru un salariu mare.

G.

See Design Patterns, part one; Introduction to get the definitions and the laws of design patterns.

Structural Patterns define the way objects are connected with other objects so changes in the system do not affect these connections. Again, the low coupling law is the base for the app designs.

There are eight patterns:

  • Adapter – converts the interface of a class into another interface clients expect;
  • Bridge – separates an object’s interface from its implementation;
  • Façade – provides a more comfortable way to deal with a library or bundle of resources;
  • Decorator – adds objects responsibilities dynamically;
  • Flyweight – reducing the number of objects;
  • Proxy – an object representing other object;
  • Composite – to compose objects into tree structures to represent part-whole hierarchies;
  • Private Class Data – restricts accessor/ mutator access.

 

Adapter

Adapter converts the interface of a class into another interface clients expect, as any cable adapter you may encountered. Usually you want to reuse an old component that offers compelling functionality, but its “view of the world” is not compatible with the architecture of the system currently being developed.

Reuse has always been painful and elusive, against everything that theorists said – OOP is about reuse, reuse and reuse. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.

Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. Adapter provides a different interface to its subject, Proxy provides the same interface. Adapter makes things work after they’re designed, Bridge makes them work before they are.

Proxy

Proxy speaks for other object. It is used to support distributed, controlled or intelligent access.

You can think about Proxy when

  • you need to delay the creation of a costly object until it is needed;
  • you have to control communication with remote objects;
  • you want to control access to objects;
  • you may want smart reference to an object – caching, locking etc.

Façade

Façade wraps a complicated subsystem with a simpler interface. An Operating System is a Façade for hardware. An eCommerce site is a Façade for ordering, billing and shipping the goods.

The Façade design captures the complexity and collaborations of the component and delegates to the appropriate methods. The client uses (is coupled to) Façade only.

Adapter and Façade are both wrappers. Façade defines a new interface, whereas Adapter uses an old interface. Adapter wraps a single object, while Façade routinely wraps multiple objects. Façade could front-end a single complex object and Adapter could wrap several legacy objects.

Bridge

The goal of Bridge is to allow you to structure your code so that you can easily add new kinds of front-end objects which are implemented with functionality in new kinds of back-end objects. Therefore, both handle and body can vary independently of each other.

Bridge is really a code-organization tool that allows you to add in any number of new front-end services that implement their operations by delegating to any number of back-end options. Using Bridge, you can accomplish this without the normal combinatorial explosion of possibilities that would otherwise occur.

Flyweight

Some programs require a huge number of objects that have some shared state among them. Each flyweight object can be divided into two pieces: the state-dependent (extrinsic) part and the state-independent (intrinsic) part. Then put them to share that intrinsic part to save memory. The key here is the HUGE number of objects. The simplicity law ask us to get it only if the memory is a pain.

Decorator

Too many classes! Decorators provide a flexible alternative to subclassing for extending functionality. Instead to create all combination at design time, you will add dynamically behavior or state to individual objects at run-time.

Note that this pattern allows responsibilities to be added to an object, not methods to an object’s interface. The interface presented to the client must remain constant as functionalities are specified.

There are some tradeoffs: coding is more complicated when using Decorators. So, try compromise – there will always be certain combinations that you will describe regularly, which would often work exactly as they are, but if you wanted to decorate them then you would use decorators to make the modifications. This will keep your code readable and maintainable.

Private Class Data

  • Encapsulate class data initialization!
  • Control write access to class attributes!
  • Separate data from methods that use it!

Yes, these are the first lessons in coding. And yes, it is about a design pattern, if you check the definition of Design Patterns.

Composite

The common objects relationship in computing – Containers that contain Containees, each of which could be a Container.

Divide your domain concepts into container classes and containee classes. Create a lowest common denominator interface that makes your containers and containees interchangeable. It should specify the behavior that needs to be exercised uniformly across all containee and container objects.

In a larger Composite problems could arise as recursion is always expensive.

G.