Welcome...



...All those moments will be lost in time, like tears in rain....

- soliloquy from Blade Runner


Bits and bytes do get lost, awash in the rain of data flow that is Internet. They slip away from us, never to found again... some of them will be captured here, many more will not... like tears in rain...



Monday, December 7, 2015

Sql server database(s) size

 When you have many databases on the server, this is the fastest way to get their size in Mb:

 exec sp_helpdb;

I wish it does break it down by data and transaction log like Disk Usage Report, it just gives the summary.




Wednesday, November 25, 2015

Programming is difficult business. It should never be undertaken in ignorance - so true!

From Douglas Crockford book, "JavaScript, The Good Parts":

The amazing thing about JavaScript is that it is possible to get work done with it
without knowing much about the language, or even knowing much about programming. It is a language with enormous expressive power. It is even better when you
know what you’re doing. Programming is difficult business. It should never be
undertaken in ignorance."


Isn't this the truth?!

 

Wednesday, August 12, 2015

TFS shelvesets

 TFS is a strange beast - some things are so easy to do, some things are unbelievably hard. And it's not easy to find answers either when you are stuck.
 Case in the point - making shelveset is very easy - you just have to click on Shelve button instead of Checkin, name it (paying attention to avoid certain characters in the naming, as usual on windows) and that's it.
 Finding a shelveset? Before latest TFS, you had to go to Files menu, then to Source Control, then to Find, then to Find Shelvesets. Not exactly path that you would expect. So, in the latest version, they added it to Pending Changes screen, under Actions link, much handier.
 That allows you to see your own shelvesets. If you want to find other people shelvesets, then nature of the beast shows up. It's hard. You have to know exact name of the person that made shelveset, and search box will not accept partial name, or not complete name (and that can include  things like company name, status etc, whatever TFS admin / IT set up).
 Only workaround I have found so far is to use wildcard "*" instead. That will show you ALL shelvesets from everybody, and you can then look for the one you want, and see exact spelling of the user name there for the next search.
 

Thursday, July 9, 2015

Setting up Autofac

 Autofac is very nice DI container, but documentation on their site is lacking on specifics.
 This is how I set up Autofac in global.asax.cs:


  protected void Application_Start()
   {
     RegisterAutofac();

     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
      
  }



and then do registration of all the things you want injected:

private void RegisterAutofac()
 {
   var builder = new ContainerBuilder();
   var config = GlobalConfiguration.Configuration;
   // all controllers are going to be built by autofac
   builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
   // concrete implementation first, interface second
   builder.RegisterType<ItemRepository>().As<IItemRepository>();

   //
   var container = builder.Build();
   config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}

Thursday, July 2, 2015

Post vs Put vs Patch in Web API

 Debates rages on and on. Why, when and how.
 My 2 cents:

  1. POST- create if you don't know resource location, but leaving it to the server to determine it and send back location of new resource to you in the header.
  2. PUT - hm, it should really be called replace. It should either create resource on specified url (by client!) or completely update it, no partial updates here.
  3. PATCH - intended for partial updates, not really available yet.
  4. POST - update - tricky one. Since we don't have PATCH yet that's the only alternative for partial updates as of now.

So something like this for POST:

// POST: api/Items
[ResponseType(typeof(BudgetItem))]
public IHttpActionResult Post(BudgetItem item)
 {
   if (ModelState.IsValid)
     {
        _itemRepository.CreateItem(item);
        return CreatedAtRoute("DefaultApi", new { id = item.Id }, item);
     }
   else
      {
      return BadRequest(ModelState);
      }
  }


And for PUT:

// PUT: api/Items/5
public IHttpActionResult Put(int id, BudgetItem item)
  {
     if (!ModelState.IsValid)
       {
           return BadRequest(ModelState);
        }
     BudgetItem oldItem = _itemRepository.GetItem(id);
     if (oldItem == null)
        {
           _itemRepository.CreateItem(item);
           return CreatedAtRoute("DefaultApi", new { id = item.Id }, item);
        }
      else
       {
          _itemRepository.UpdateItem(item);
          return Ok(item);
       }
   }

Wednesday, June 10, 2015

400s vs 500s error codes in REST

 The best explanation I've seen so far:

http://restcookbook.com/HTTP%20Methods/400-vs-500/


4xx codes are used to tell the client that a fault has taken place on THEIR side. They should not retransmit the same request again, but fix the error first.
5xx codes tell the client something happened on the server and their request by itself was perfectly valid. The client can continue and try again with the request without modification.

Friday, May 1, 2015

Removing item from dictionary in C#

  There is a method aptly named Remove:

  public bool Remove
  (
 TKey key
  )

  dict.Remove(keyId)

 It will not raise the exception if key does not exist -  handy!

  If you do want to check existence of the key anyways, it will return false if it  is unable to find a key (or unable to remove it for some other odd reason).

Thursday, April 30, 2015

Another framework

 There is a framework called Vanilla-JS. No, there is NOT :) It's a joke people!

 http://vanilla-js.com/

Sql Server user and login problem

 I run into the issue of having user and login disconnect in my local database. What happened was that I restored database from testing server, and that disconnected user and login. They both existed in database, but user was of type SQL Server user WITHOUT Login, even if that login right there.
 After lots of searching, solution that works was - DROP THE USER and Recreate User. That will give you chance to relink them (SID update) and it works. All other solutions just didn't work - I couldn't find any orphaned users, I couldn't do Alter user...
 Just recreate the user :)