It’s New Year’s Day and I am finishing the last of my traditional holiday vacation. Tomorrow, I will return to my office after a hiatus of almost two weeks and am sure I will spend most of the day inundated by emails and following up on the projects that were in process when I left. But today, I was reading through recent blog posts by two of our more prolific writers here on LessThanDot, Onpnt (Ted Krueger) with Blogging isn’t easy unless you have support and SQLDenis (Denis Gobo) with Ah yes, those pesky resolutions. I have to admit, both of them have inspired me with my own resolutions and blogging.
This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.
It is 6:22 AM and I am the only person awake in our house. I didn’t really wanted to write a post like this but since everyone else is sleeping and I don’t want to wake them by doing other stuff, here it goes. There are a couple of things I want to accomplish this year, here is what those things are. Read more technical books I read a decent amount of books every year, in 2012 I managed to read 51 books, you can see all of them here http://pinterest.com/denisgobo/books-i-read-in-2012/
Over the past year, and previous years, writing blogs, articles for various publications and even books, has been one of the most enjoyable aspects to my work in the data and professional development world. Given today is the last day of 2012, this year I think was great for writing and one that I have improved upon my skills, development and writing. Something I’d like to go into the New Year with is a special thanks for a few people that have made my ability and ambition for writing possible. Mostly, Jes Borland (B | T) has been a huge part in this. Back when I wrote my 4th or 5th blog, I was horrible at writing. My grammar was terrible and my mind always worked far faster than my typing skills could. This led to some pretty craptastic articles. Luckily, I met Jes and soon after, she started helping me greatly with my writing by reviewing almost all of the articles I’ve written. With that and the comments and edits to my articles, I’ve learned more about writing and slowing my roll to make my mind and typing more in unison. I can truly say, I would not be writing an eighth of what I do up to now, without that help.
I received an email the other day asking why, when running SHOW_STATISTICS, a person was always seeing the primary key in the statistics column density and other output, when the primary key was not part of the index the statistics were created from. This is a great question and relates to an article I’m writing on selectivity and ordering in the creation of an index while writing queries. I thought a quick post would be great on it, since the answer isn’t truly standing out when you search for the reason statistics on nonclustered indexes will always contain the primary key or unique constraint column (on a table that is clustered).
Introduction Yesterday I was adding a pdf feature to my Nancy service. And I was outputting my objects to the pdf like this. foreach (var prop in model.GetType().GetProperties()) { oDoc.Add(new Paragraph(prop.Name + ":" + prop.GetValue(model).ToString())); }``` But we all know this is far from finished and will only work in the most simple of cases, once you add complex types to your type the results will be less than optimal. Of course you are not alone in this world and other people have had to do this to. And Demis Bellot even made a nuget package out of his solution. So here is Servicestack.Text and the [Dump][2] extension method and friends. ## Dump So go ahead and look for servicestack.text on nuget and add it to your project. First of all I would like to change my method above to use the Dump() method. And so my method now looks like this. ```chsarp protected virtual Action<Stream> GetPdfContents(TModel model) { return stream => { var oDoc = new Document(PageSize.A4); PdfWriter.GetInstance(oDoc, stream); oDoc.Open(); oDoc.Add(new Paragraph(model.Dump())); oDoc.Close(); }; }``` So you just need you object and call the Dump() extension method on it and the output will look like this. > { > propertyname: value, > propertyname2: value > } Nicely formatted JSV. Yep that’s it. The output now looks like this. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/servicestacktext/servicestacktext1.png?mtime=1356945714"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/servicestacktext/servicestacktext1.png?mtime=1356945714" width="532" height="670" /></a> </div> Or I could output a list of objects and that would look like this. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/servicestacktext/servicestacktext2.png?mtime=1356945965"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/servicestacktext/servicestacktext2.png?mtime=1356945965" width="594" height="723" /></a> </div> And that is very convenient. This is the the same as doing SerializeAndFormat(). ## PrintDump And do you remember this code? ```csharp var trees = http.Get("http://localhost:65367/trees"); foreach (var t in trees.DynamicBody.Trees) { Console.WriteLine(t.Id); Console.WriteLine(t.Genus); } var result = http.Get("http://localhost:65367/trees/1"); var tree = result.DynamicBody; Console.WriteLine(tree.Id); Console.WriteLine(tree.Genus); ``` Lots of Console.Writelines and not very robust. ```csharp var trees = http.Get("http://localhost:65367/trees"); trees.StaticBody<Object>().PrintDump(); var result = http.Get("http://localhost:65367/trees/1"); result.StaticBody<Object>().PrintDump();``` PrintDup won’t work on dynamic objects so I switched to a staticobject, but easyhttp doesn’t mind. And I get this as the result. > { > Trees: > [ > { > Id: 1, > Genus: Fagus > }, > { > Id: 2, > Genus: Quercus > }, > { > Id: 3, > Genus: Betula > }, > { > Id: 4, > Genus: Fagus > }, > { > Id: 5, > Genus: Quercus > }, > { > Id: 6, > Genus: Betula > }, > { > Id: 7, > Genus: Fagus > }, > { > Id: 8, > Genus: Quercus > }, > { > Id: 9, > Genus: Betula > }, > { > Id: 10, > Genus: Fagus > }, > { > Id: 11, > Genus: Quercus > }, > { > Id: 12, > Genus: Betula > }, > { > Id: 13, > Genus: Fagus > }, > { > Id: 14, > Genus: Quercus > }, > { > Id: 15, > Genus: Betula > } > ], > NumberOfTrees: 15 > } > { > Id: 1, > Genus: Fagus > } Genius. ## SerializeToString And if you on’t like the formatting then you can use SerializeToString(). ```csharp var trees = http.Get("http://localhost:65367/trees"); Console.WriteLine(trees.StaticBody<Object>().SerializeToString()); var result = http.Get("http://localhost:65367/trees/1"); Console.WriteLine(result.StaticBody<Object>().SerializeToString()); Which will have this kind of output.
Introduction So I have been doing this Nancy series for a while now and the demoproject is [still up at Github][1]. Today I’m going to try and return a pdf from a request. The Response. So instead of returning json or html or some such I want to return a pdf page. I guess I could write a complete viewengine if needed but I don’t need that I just want my trees module to return a pdf in a certain format when requested.
In yesterday’s post we looked at Searches, Countries and Content. Today we are looking at Devices, Operating Systems and Browsers. Microsoft came out with a new operating system at the end of October. during the month of December, Windows 8 accounted for 7.88% of all Windows visitors. We’ll have to see how long it will take before Windows 8 passes Windows XP. Mobile Devices This table list all the mobile devices that accessed this site aggregated over the whole year. No surprise, the iPad is number 1, the iPhone is number 2
Introduction I have been using Nancy for a few weeks now and made a demo application that you can find on Github. Today I will add the ability for you to add a picture to a user. The upload For this we need to change our UsersModule and add a few methods. First we add a get so that we can show a page with the userdata and an upload form. Something like this.
I like powershell and from time to time I even use it. This time I needed to rename a lot of files in some directory I had. First thing to note is that these files are on a NAS. No problem just do cd \192.168.1.152series``` and you’re on that drive. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/powershell/powershellbatchrename2.png?mtime=1356627627"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/powershell/powershellbatchrename2.png?mtime=1356627627" width="813" height="252" /></a> </div> That doesn’t work with the normal commandline BTW. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/powershell/powershellbatchrename1.png?mtime=1356627545"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/powershell/powershellbatchrename1.png?mtime=1356627545" width="677" height="343" /></a> </div> So now we are there we can see we have bunch of files. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/powershell/powershellbatchrename3.png?mtime=1356627807"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/powershell/powershellbatchrename3.png?mtime=1356627807" width="580" height="475" /></a> </div> It is clear that these files don’t say a lot about the contents, I will want to fix that. I want to prefix them all with Stargate. Easy just cd your way to that directory <code class="codespan">Stargate/SG1/Season 1</code> and do this. Dir *.mkv | rename-item -newname { “Stargate " + $_.Name}``` Yep that’s one line of code.
Every year I like to do a couple of posts showing some analytics about the visitors to this site In this post we will be looking at the searches, the content and the countries that visitors came from Content Here are the top 25 most visited pages on this site during the year 2012. Page Title <th> Percentage </th> </tr> <tr> <td> <a href="/summary.php">All Blogs</a> </td> <td> 15.98% </td> </tr> <tr> <td> <a href="/index.php/ITProfessionals/EthicsIT/collection-of-puzzles-for-programmers">Collection Of Puzzles For Programmers</a> </td> <td> 11.40% </td> </tr> <tr> <td> <a href="http://forum.lessthandot.com/search.php?search_id=active_topics">View active topics</a> </td> <td> 8.92% </td> </tr> <tr> <td> <a href="http://lessthandot.com/">Launchpad</a> </td> <td> 7.90% </td> </tr> <tr> <td> <a href="http://sqlcop.lessthandot.com/">SqlCop</a> </td> <td> 6.15% </td> </tr> <tr> <td> <a href="/index.php/ITProfessionals/ProfessionalDevelopment/should-i-abandon-vb-net">Should I abandon VB.Net?</a> </td> <td> 4.99% </td> </tr> <tr> <td> <a href="http://lessthandot.com/">Index page</a> </td> <td> 4.80% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DataDesign/calculating-mean-median-and-mode-with-sq">Calculating Mean, Median and Mode with SQL Server</a> </td> <td> 4.62% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DataDesign/the-ten-most-asked-sql-server-questions--1">The Ten Most Asked SQL Server Questions And Their Answers</a> </td> <td> 4.60% </td> </tr> <tr> <td> <a href="/index.php/ITProfessionals/ITProcesses/trying-the-stand-up-desk">Trying the Stand-Up Desk</a> </td> <td> 3.09% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DataDesign/sql-server-zipcode-latitude-longitude-pr">SQL Server Zipcode Latitude/Longitude proximity distance search</a> </td> <td> 3.06% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DBProgramming/create-xml-files-out-of-sql-server-with-">Create XML Files Out Of SQL Server With SSIS And FOR XML Syntax</a> </td> <td> 2.79% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DBAdmin/title-12">6 ways to import data into SQL Server</a> </td> <td> 2.30% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DataDesign/sql-server-2008-proximity-search-with-th">SQL Server 2008 Proximity Search With The Geography Data Type</a> </td> <td> 2.29% </td> </tr> <tr> <td> <a href="/index.php/ITProfessionals/EthicsIT/how-to-enable-godmode-on-windows-7">How To Enable GodMode On Windows 7</a> </td> <td> 2.25% </td> </tr> <tr> <td> <a href="/index.php/ITProfessionals/ProfessionalDevelopment/be-mindful-with-your-code">Be Mindful With Your Code</a> </td> <td> 2.21% </td> </tr> <tr> <td> <a href="http://wiki.lessthandot.com/index.php/Kill_All_Active_Connections_To_A_Database">Kill All Active Connections To A Database – Wiki</a> </td> <td> 2.19% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DBProgramming/MSSQLServer/delete-all-data-in-database-when-you-hav">Delete all data in database (when you have FKs)</a> </td> <td> 1.81% </td> </tr> <tr> <td> <a href="http://wiki.lessthandot.com/index.php/SQL_Server_Programming_Hacks_-_100%2B_List">SQL Server Programming Hacks – 100+ List – Wiki</a> </td> <td> 1.80% </td> </tr> <tr> <td> <a href="http://forum.lessthandot.com/viewforum.php?f=102">View forum – Programmer Puzzles</a> </td> <td> 1.76% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DataDesign/think-carefully-which-sql-server-you-wan">Working with 32 bit providers and 64 bit SQL Server</a> </td> <td> 1.73% </td> </tr> <tr> <td> <a href="/index.php/DataMgmt/DataDesign/extracting-numbers-with-sql-server">Extracting numbers with SQL Server</a> </td> <td> 1.71% </td> </tr> <tr> <td> <a href="http://wiki.lessthandot.com/index.php/Cursors_and_How_to_Avoid_Them">Cursors and How to Avoid Them – Wiki</a> </td> <td> 1.69% </td> </tr> Searches Here is a list of the most used search terms, as you can see it is mostly SQL related, this makes sense since most of the content is SQL related