Json.NET and Serializing only base class properties

I was just working with Json.NET in C# and was looking for a solution to create a JSON-String from an object where I only wanted to put in the properties of the base type, as I have stored subtypes in memory which contain additional ViewModel properties that were unneeded as I only needed the business data. As I didn’t find anything fitting via Google, I researched how to build a custom ContractResolver that only serializes the Properties belonging to my business model class type T:

public class DerivedTypeFilterContractResolver<T> : 
        DefaultContractResolver
{
  protected override JsonProperty CreateProperty(
        MemberInfo member, 
        MemberSerialization memberSerialization)
  {
    JsonProperty property = base.CreateProperty(
         member, memberSerialization);
    if (property.DeclaringType == typeof(T))
    {
        property.ShouldSerialize =
          instance => false;
    }
    return property;
}
One comment so far, add another

Routine, Change and Failure

MonsterandAngel_id_8454306326_CC_ND_BY_h.koppdelaney_16230215@N08

Whenever I read that you should embrace failure, I think that many people won’t get the point.

The human mind loves routine. Routine is a series of steps you’ve done before, in a way that’s always the same. When you know something works in a certain way, it’s a safe feeling that you know what’s coming. It’s the opposite of danger, and the fear that’s connected to danger.

When you read somewhere that you should embrace failure, they really mean that you should change. Change always has a positive effect, and if it hasn’t (you failed!) you can usually change again and learn something in the process, advancing you overall.

What keeps you from change is when you never break your routine.


Picture: Creative Commons Attribution-No Derivative Works 2.0 Generic License  by  h.koppdelaney

One comment so far, add another

Mac OS X Customizability – Part 2: Finder, Browsing, Touchpad and Windows 7 Features

Related: Mac OS X Customizability – Part 1: Desktop

I wish I had known this stuff earlier, so here you go with part 2. This will especially be interesting for people who think the Mac misses some features they like on Windows 7, or that you wonder why Apple didn’t build em in. Small side-note: I use A LOT of apps that modify global input, but it doesn’t cause any problems at all. There was one single incompatibility that KeyRemapForMacbook could fix for me.

The first tool I want to mention is BetterTouchTool which does all sorts of nice & crazy things. For example, it includes the Window Snapping behavior from Windows 7, where you can drag a window somewhere and it maximizes like this:

desktop_window_snapping_mac

The tool is free, and does a lot more in this regard, and as you can see from this screenshot, you can configure the hell out of BTT (oh, and the window moving part on the other settings screen is also really nice, like “move the window under the cursor when I hold fn“):

bttWindowSnapping

I don’t use a mouse anymore, because BetterTouchTool does LOADs of stuff by configuring gestures for my touchpad. As an example what it can do, I show you the following screenshot with the Chrome settings for nicer tabbed browsing:

BTTchromesettings

Swipe three fingers up to open a tab, down to close it, and tip-taps left and right to hit the shortcuts for switch to left or right tab. Nice right? How cool would it be if Finder had tabs and worked this way? Enter XtraFinder:

XtraFinderDualTabs

Yes, with the tabbed browsing in Finder, I defined the same stuff for the finder that I also defined above for the browser in BetterTouchTool, which looks like this:

bttfindersettings

XtraFinder is free too, and it also adds a lot of useful stuff freshly converted Windows users miss, like “Create new .txt here”, but also stuff very handy on the Mac like “Create Symlink”, “Open in Terminal” or “Copy Path (with various syntax modes like path, windows path, file-URL, etc…)”. See for yourself some examples as screenshots:

XtraFinderNewFile

Xtra_path

The only thing missing at this point is a fast way to jump to exactly the right folder or file that you need right now. On Windows, I used everything for that, on Mac my first choice was intuitively using Spotlight. Which is fine, it’s just that the last must-have app in this post – Alfred – is faster and better and more customizable. Just install and use it, you’ll see:

alfred

Alfred can do a lot of stuff, integrate 1Password (I’m not going to show you a screenshot, but that’s a must have app too), but generally it’s just a great search tool. Btw. the guys behind Alfred have just released the beta of the next major version, which is a complete rewrite that will support some fascinating things like a Google Instant search right on your desktop.

alfred_clipboard_history

One more giant feature I need to post a screenshot for: Alfred includes a VERY good searchable clipboard history. In the next post of this series, I’ll likely write about automation of basically every thinkable workflow using Keyboard Maestro.

2 comments so far, add yours

Hay Day Hints, Tips and Tricks

Just want to note that I was seriously infected with a free game called Hay-Day. I wrote up my hints, tips and tricks for beginner in a small, ugly-themed Tumblr. Have fun with that, but don’t expect more – I quit, as it wasn’t free but cost a lot of time :-)

2 comments so far, add yours

Mac OS X Customizability – Part 1: Desktop

Waiting for an 21GB game to install, I found time for a short burst of blog posts about really cool stuff you can do to customize your Mac OS X experience. I wish I had known this stuff earlier, so here you go with part 1.

Let’s customize the Desktop with dynamic data. This is mine:

fullscreen

 

If you want dynamic text on your desktop too, download GeekTool from the Mac App Store. For the quotes, you can use the settings you see on the screenshot with my ruby script (download herethat gets quotes from http://feeds.feedburner.com/quotationspage/qotd. For the process list, use the following settings and command:

geektoolProcesses

top -l 1 | awk '/PhysMem/ {print "Used RAM: " $8 " Free: " $10}';echo "";echo "  PID  CPU% RAM_MB  Process";ps -arcwwwxo "pid %cpu rss command" | egrep "$1" | grep -v grep | head -12 | tail -11

The calendar stuff in the middle are multiple “geeklets” that use the following commands to get the different parts of the calendar and that are styled slightly different:

date +%A (outputs “Friday” in my german localization)

date +%d.; (outputs “08.”)

date +%B (outputs “February”)

date '+%H:%M' (outputs “23:46”)

The resulting calendar then might look like this, if you’ve styled the geeklets like I did and positioned them in the same way (the borders will vanish, when GeekTool is not the frontmost app):

calendarGeekTool

By the way, when you have so many strange apps installed (I have), your appbar gets icon creep. But if you saw my screenshots above, it wasn’t so bad, was it? May I introduce: Bartender. Look at this

bartender

Bartender lets you configure what you want to see, what you don’t want to see and what is only shown in the Bartender bar that opens when you click it.

Part 2 of this customizability posts will follow soon with a better finder and better touch input.

One comment so far, add another