This is a mirror of official site: http://jasper-net.blogspot.com/

What does the langversion switch do?

| Thursday, April 18, 2013
The C# compiler has a /langversion switch that is rarely used; most people do not know what it is for, and if asked to guess, most guess wrong. So let me disabuse you of your wrong guess right away: the purpose of the langversion flag is not to decide what C# language version to use. It is not a "go into compatibility mode" switch or a "use a previous version of the compiler" switch. The only effect of the langversion switch is to put the compiler in a mode in which use of features from a version of the language higher than the given version cause the compiler to emit an error.

Let me illustrate with a hilariously contrived example:

class C
{
    public static bool operator < (C c1, C c2) { return true; }
    public static bool operator > (C c1, C c2) { return true; }
    public static bool operator < (bool b1, C c2) { return true; }
    public static bool operator > (bool b1, C c2) { return true; }

    static C H = new C();
    static C I = new C();
    static C J = new C();
    static void G(bool b) { }
    static void Main()
    {
        G ( H < I > ( J ) );
    }
}

This ridiculous program compiles successfully in C# 1.0; it invokes the < operator on H and I, and then invokes the > operator on the resulting bool and J.

QR: Inline image 1

Posted via email from Jasper-net

Microsoft.Bcl.Async is Now Stable

|
Inline image 2

It’s done. About five months ago, we shipped our Microsoft.Bcl.Async NuGet package which provides support for the async/await keywords for pre-.NET 4.5 platforms, such as .NET 4, Silverlight 4, and Windows Phone 7.5. Of course, this includes support for portable class libraries as well.

We believe we’ve baked Microsoft.Bcl.Async enough to flip the switch and mark it as stable. This might not sound like a big deal but it is the NuGet equivalent of shipping an RTM.

QR: Inline image 1

Posted via email from Jasper-net

My relationship with SOLID - The big O

|
Open closed is dead, long live Open closed

I'm blogging about SOLID for some reason, and now we're onto the beast that set me off:

OCP

Yikes

 They are “Open For Extension”. This means that the behavior of the module can be extended. That we can make the module behave in new and different ways as the requirements of the application change, or to meet the needs of new applications.
and

 They are “Closed for Modiļ¬cation”. The source code of such a module is inviolate. No one is allowed to make source code changes to it.
Thanks Uncle Bob, you're right, this is over-stated, and because it's so over stated, I believe it to be the cause of so many of the over-designed pieces of crap I've had to deal with in my career :-)

This is the conversation I imagine developers having with themselves when writing this stuff, I don't have to imagine too hard because I've been there too:

 What if somebody at some point wants to change this so they can have another behaviour for this value, I'd better use the strategy pattern here instead of this switch statement, but oh my word now I've done that what if somebody wants to use this code from some other system than this one, I'd better stick a command system in front of this and use double dispatch for handling them - but wait, what if other code needs to react from this and do something else, I'd better raise a pile of events, but what if those aren't enough I'd better make sure I split all this behaviours out into their own interfaces so they can be overridden and...
And on it goes until suddenly what was a couple of classes behind a controller or presenter blow up into a mess of a hundred classes that all do the square root of diddly squat, but together manage to cause a lot of headaches for anybody coming across the code in the future.

Now, I'm sure this wasn't the intent behind these statements, and it sure isn't now - but you know what?

Read more: Rob Ashton
QR: Inline image 1

Posted via email from Jasper-net

How to Watch YouTube Videos in VLC Media Player

|
Inline image 2

How to Watch YouTube Videos in VLC Media Player
You will first need to open VLC, then click on the Media menu followed by Open Network Stream…

Read more: How-to geek
QR: Inline image 1

Posted via email from Jasper-net

If you don't know what you're going to do with the answer to a question, then there's not much point in making others work hard to answer it

|
A customer asked the following question:

We've found that on Windows XP, when we call the XYZ function with the Awesome flag, the function fails for no apparent reason. However, it works correctly on Windows 7. Do you have any ideas about this?

So far, the customer has described what they have observed, but they haven't actually asked a question. It's just nostalgia, and nostalgia is not a question. (I'm rejecting "Do you have an ideas about this?" as a question because it too vague to be a meaningful question.)

Please be more specific about your question. Do you want to obtain Windows 7-style behavior on Windows XP? Do you want to obtain Windows XP-style behavior on Windows 7? Do you merely want to understand why the two behave differently?

The customer replied,

Why do they behave differently? Was it a new design for Windows 7? If so, how do the two implementations differ?

I fired up a handy copy of Windows XP in a virtual machine and started stepping through the code, and then I stopped and realized I was about to do a few hours' worth of investigation for no clear benefit.

QR: Inline image 1

Posted via email from Jasper-net

How to Extend Your Office 2013/365 Trial to 180 Days

|
Inline image 2

In recent years it has become common for Microsoft to release trial or preview versions of its big-name products. This has been the case with Windows 8 as well as Office 2013 giving consumer the chance to try before they buy. If you downloaded the trial version of the suite, you can gain some extra try-out time with this handy hack.

The trial version of Office 365 is only meant to be used for 30 days. After this time you are expected to by a license or stop using the software. In practice, Office does not become unusable, but instead enters a ‘reduced functionality’ mode.

But if you are not sure about committing to the purchase, you can extend you trial period so you can test drive the office suite for a little longer.

It is possible to ‘rearm’ the trial version of the software five times – essentially giving you six 30-day trial periods, or 180 days in total.

While there are various tools that can be downloaded that can do this job for you, there’s no need – everything you require is already available to you. The only thing you need to remember is to run through the rearming process before you trial periods run out; make sure you do it on the thirtieth day of the trial.

...
...

You can also navigate direct to C:\Program Files\Common Files\Microsoft Shared\OfficeSoftwareProtectionPlatform or C:\Program Files (x86)\Common Files\Microsoft Shared\OfficeSoftwareProtectionPlatform and type OSPPREARM.EXE into Explorer’s address bar before hitting Enter.

That’s all there is to it. It’s not quite a free copy of Office, but you do get to use it for a little longer.

Read more: How-to geek
QR: Inline image 1

Posted via email from Jasper-net

Big list of LINQ interview questions and answers compiled

| Wednesday, April 17, 2013
I have had a number of users ping me asking about writing interview questions on LINQ. I actually have a 8 detailed posts on LINQ interview questions. Here is a compilation of the posts:

(more....)

QR: Inline image 1

Posted via email from Jasper-net

Postgres 9.3 feature highlight: JSON data generation

|
Postgres 9.2 has introduced JSON as a server data type. At this point, the data was simply stored on server side with integrated wrappers checking that data had a correct JSON format. It was a good first step in order to store directly JSON data on server side but core features in 9.2 have its limitations in terms of JSON data manipulation and transformation.

Two new sets of JSON features have been added to PostgreSQL 9.3 planned to be released this year: functions related to data generation and a new set of APIs for data processing. The one this post deals with the ability to generate JSON data based on existing data types. The second set of features (operators and new processing functions) will be explained in a future post.

So… Functions for JSON data generation have been added by this commit.
commit 38fb4d978c5bfc377ef979e2595e3472744a3b05
Author: Andrew Dunstan 
Date: Sun Mar 10 17:35:36 2013 -0400
 
JSON generation improvements.
 
This adds the following:
 
 json_agg(anyrecord) -> json
 to_json(any) -> json
 hstore_to_json(hstore) -> json (also used as a cast)
 hstore_to_json_loose(hstore) -> json
 
The last provides heuristic treatment of numbers and booleans.
 
Also, in json generation, if any non-builtin type has a cast to json,
that function is used instead of the type's output function.
 
Andrew Dunstan, reviewed by Steve Singer.
Catalog version bumped.

The first function called to_json permits to return a given value as valid JSON.
postgres=# create table aa (a bool, b text);
CREATE TABLE
postgres=# INSERT INTO aa VALUES (true, 'Hello "Darling"');
INSERT 0 1
postgres=# INSERT INTO aa VALUES (false, NULL);
INSERT 0 1
postgres=# SELECT to_json(a) AS bool_json, to_json(b) AS txt_json FROM aa;
bool_json | txt_json
-----------+---------------------
true | "Hello \"Darling\""
false |
(2 rows)

Boolean values are returned as plain true/false, texts are quoted as valid JSON fields.

json_agg is a function that can transform a record into a JSON array.
postgres=# SELECT json_agg(aa) FROM aa;
json_agg
---------------------------------------
[{"a":true,"b":"Hello \"Darling\""}, +
{"a":false,"b":null}]
(1 row)

Read more: Michael Paquier
QR: Inline image 1

Posted via email from Jasper-net

“Hacking Secret Ciphers with Python” Released

|
Inline image 1

My third book, Hacking Secret Ciphers with Python, is finished. It is free to download under a Creative Commons license, and available for purchase as a physical book on Amazon for $25 (which qualifies it for free shipping). This book is aimed at people who have no experience programming or with cryptography. The book goes through writing Python programs that not only implement several ciphers but also can hack these ciphers.

QR: Inline image 2

Posted via email from Jasper-net

Using GridFS in MongoDb from C#

|
GridFS is a specification for storing large files in MongoDB. GridFS will chunk a file into documents, and the official C# driver supports GridFS.

The following class wraps some of the driver classes (MongoDatabase and MongoGridFS):

public class MongoGridFs
{
    private readonly MongoDatabase _db;
    private readonly MongoGridFS _gridFs;
 
    public MongoGridFs(MongoDatabase db)
    {
        _db = db;
        _gridFs = _db.GridFS;
    }
 
    public ObjectId AddFile(Stream fileStream, string fileName)
    {
        var fileInfo = _gridFs.Upload(fileStream, fileName);
        return (ObjectId)fileInfo.Id;
    }
 
    public Stream GetFile(ObjectId id)
    {
        var file = _gridFs.FindOneById(id);
        return file.OpenRead();           
    }
}
The following code uses the above class to put a file into MongoDB, then read it back out.

var fileName = "clip_image071.jpg";
 
var client = new MongoClient();
var server = client.GetServer();
var database = server.GetDatabase("testdb");
var gridFs = new MongoGridFs(database);

Read more: Ode to code
QR: Inline image 1

Posted via email from Jasper-net