The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140508-Delphi-2007--Project-Options--Cannot-Edit-Application-Title-HelpFile-Icon-Theming

    20140430-Fiddler-Filter-Actions-Button-Run-Filterset-now

    20140424-Windows-7-free-disk-space

    More Photos
  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,501 other followers

Archive for the ‘Software Development’ Category

anoymyous type trick: Check if KeyValuePair exists with LINQ’s FirstOrDefault – via Stack Overflow

Posted by jpluimers on 2015/08/27

When you have a Dictionary<TKey, TValue>, then LINQ results will get you a enumerables of KeyValuePair<TKey, TValue>.

Since KeyValuePair is a struct, selecting FirstOrDefault will not get you a null, but a default(KeyValuePair<TKey, TValue>) which is a lot harder to handle than null.

Sometimes, being able to get a null out of FirstOrDefault is very useful, so a bit thank you to Marc Gravell for answering this very neat trick:

If you just care about existence, you could use ContainsValue(0) or Any(p => p.Value == 0) instead? Searching by value is unusual for a Dictionary<,>; if you were searching by key, you could use TryGetValue.

One other approach:

       var record = data.Where(p => p.Value == 1)
            .Select(p => new { Key = p.Key, Value = p.Value })
            .FirstOrDefault();

This returns a class – so will be null if not found.

The trick is this portion:

p => new { Key = p.Key, Value = p.Value }

It introduces an anonymous type with two fields: Key and Value. (Note you can introduce any anonymous type here). Since these are classes, FirstOrDefault will return null if nothing was found.

–jeroen

via:

Posted in .NET, Software Development, Development, C#, C# 3.0, C# 4.0, .NET 4.5, C# 5.0, .NET 3.5, .NET 4.0, C# 6 (Roslyn) | Leave a Comment »

for %n = 1 to 100 step 1 do: windows – Batch script loop – Stack Overflow

Posted by jpluimers on 2015/08/26

Thanks Jon for answering this:

for /l is your friend:

for /l %x in (1, 1, 100) do echo %x

Starts at 1, steps by one, and finishes at 100.

Use two %s if it’s in a batch file

for /l %%x in (1, 1, 100) do echo %%x

–jeroen

via: windows – Batch script loop – Stack Overflow.

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

Programmers’ hardest tasks

Posted by jpluimers on 2015/08/25

It took me a while to find the original illustration (especially as it was copied so often in low quality), but below it is.

Martin Wienold made a great joke based on it last year:

There are only two hard problems

  1. naming things
  2. cache invalidation
  3. off-by-one errors

–jeroen

via: G+; Programmers’ hardest tasks.

Original (October 2013): Don’t go into programming if you don’t have a good thesaurus | ITworld.

Programmer's Hardest Tasks

Programmer’s Hardest Tasks

 

Posted in Development, Software Development | Leave a Comment »

Was ist Cloud? Great presentation including transcript by Kristian Köhntopp.

Posted by jpluimers on 2015/08/23

When one of my DevOps friends asks: Was ist Cloud?.

Kristian Köhntopp even published it as a SlideShare deck with transcript: Was ist Cloud?.

There is even a video: Froscon “Was ist Cloud?” – Video.

Thanks a million, Kris, this is very much worth reading for anybody doing Ops, Dev or DevOps.

There is even a

If you can’t read German: tough luck (;

–jeroen

Read the rest of this entry »

Posted in Cloud, Development, Firewall, Infrastructure, Software Development | Leave a Comment »

GoF Patterns in Delphi | Implementations of the famous Gang of Four Design Patterns in Delphi language – via Nick Hodges

Posted by jpluimers on 2015/08/20

Thanks to Nick Hodges for having Delphi-losophy | Flotsam and Jetsam #88 point me to GoF Patterns in Delphi | Implementations of the famous Gang of Four Design Patterns in Delphi language.

–jeroen

Posted in Delphi, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Development, Software Development | 1 Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 1,501 other followers

%d bloggers like this: