Skip to main content

Posts

Moving to Medium

It's been a long time since I want to give medium a try, and finally, I made some time to do it.
To get started on the new platform, I'll be doing series on "Getting programming concepts, languages and tools". If it sounds interesting to you, please take a look at the first post Getting AWK and spread the word if you like it.

I'm not going to migrate old entries to the new web site. They will remain here safe and sound!

As usual, thanks for reading!
Recent posts

Vim - Replace word under cursor

The way you edit text in vim is pretty much by running commands, you have a few shortcuts here and there, but most of the time is just running commands.

While I really like this approach, I do miss a replace word under cursor shortcut. To do that in "plain" vim, you have to type:

:%s/<C-r><C-w>/type_new_word_here/gc

(Where <C-r> stands for Ctrl+R, and <C-w> for Ctrl+W. That's a bit of a stretch on the mac where you only have a Left Ctrl key).

What the previous command does is to look for the word under cursor in the current file and ask you if you want to replace it with the word you have entered in the second part of the command. The flag gc tells vim that the action is global and that it must to ask you for confirmation before replacing matches.

There is not a whole lotta of typing but we can do better.

The good news is that with a bit of vimscript, you can avoid acrobatic motions and start replacing words with a copule of keystrokes.

This is the…

How to show excel files inside the .NET Webbrowser Control

If you are reading this, chances are you been banging your head against the wall for a couple of hours (or even days) trying to show excel files inside the WinForms webbrowser control. Possible reasons you ended up in here: You had working code that got broke after upgrading from Win 7. Your code doesn’t work the same way between machines running different (newer) versions of IE. A download box pops up every time your app tries to show an excel file inside the webbrowser control (you wanna show the actual content). You just have no clue on how to get excel working into the .NET embedded webbrowser control. You are trying to implement IInternetSecurityManager and don’t know where to start. (Or how don’t know how to delegate calls to your security manager). Among many other, maybe…..
Yes, COM is a PITA, so is ActiveX and IE (Embedded or full for that matter). And no, showing excel files inside the webbrowser control shouldn’t be that hard, but sometimes we have to deal with what we have at ha…

Ruby and CQRS - Command methods should return nothing

CQRS stands for Command Query Responsibility Segregation and the basic rules are:
Commands - Perform (side effects) actions on the system and don't return values.
Queries  - Return values but can't touch the system's state.
Idealy, you don't mix them. Hence you can say, commands are dangerous, and
queries are safe.

Now, ruby doesn't have a specific type to say: this method (command) returns nothing, like void in C and other languages. So, the question is: How do you state that a particular method returns nothing?

Based on comments from the ruby mailing list, people are using these approaches;
1. Return self.
2. Return nil.
3. Implicit return (which in general, ends up being nil).

If I'd have to pick one, I'd go with the last one, but I also like to throw
another option into the mix....
Why don't create a class for this particular use case? Let's say, Nothing!

module Nothing
class Nothing
end

def nothing
@nothing ||= Nothing.new
end
end

class CommandQuery…

Contest is here to stay

For a long time the .NET's unit testing landscape hasn't changed that much... sure, new frameworks arrived, but they were almost the same thing with a subtle syntax twist, instead using [Test] they use [Fact] or different ways to specify setups and so on, but the essence was the same... Attributes based libraries with GUI oriented test runners. There is nothing wrong with that perse, but I guess everybody would agree that they are hard to use if you are working on plaint text editor like vi or emacs. In this context, contest was born as an alternative to IDE oriented tools for those who prefer consoles and text editors. The way the art of programming was meant to be ;) For an elevator pitch, please refer to this codeproject article.  For docs and getting started guides go the contest's repo on github. And of course, if you have any question, fell free to contact me.

Install Command-T on Windows

Command-T is one of the most powerful Vim's plugins but install it on a Windows box could be a bit of pain in the ass little frustrating ;). Here I'll post a step by step guide on how to install this plugin from scratch.
First of all, you will need a copy of Vim compiled with ruby support (+ruby) which ins't the case of the default version that you get from the official site. While you can compile Vim by yourself, you can also download an already compiled version from here http://wyw.dcweb.cn/download.asp?path=vim&file=gvim74.zip (ruby 2.0) Once your download completes, extract vim.exe and gvim.exe and copy them into “C:\Program Files (x86)\Vim\Vim74”
Now, got to your command prompt and run: vim –version. Among a bunch of stuff, you should see +ruby.
In addition to the modified version of Vim, you will also have to install ruby 2.0. If you haven't already, go to http://rubyinstaller.org/downloads/ and download de x86 version of Ruby 2.0 and the according RubyDevKit. (It…

Oneway ticket from Visual Studio to Vim

Not so while ago If you had asked: Would you ever leave Visual Studio (+ReSharper and tools)?. The answer would be: “Hell No!, Why on earth I'll leave the most powerful IDE ever built?!
But as the time goes by, I've changed my mind... Lately I been working on Mac, Linux and Windows, doing .NET, JavaScript, TypeScript, Ruby, HTML, CSS, some SQL and batch/shell scripts. Having and editor that works (almost) the same way in all of these platforms is a big win for me. Not to mention that I can code in any language I want with out switching editors.
Here is a short a short list features that made me change my mind. * Cross platform support. (Big one). * Lightweight. (When in the road, your battery will last longer). * Fast as hell. You won't be waiting for minutes to open solutions. * You can code in any language you want. * Tiny footprint. You don't need 8 GB of disk's space just to install the tool. * Already installed on most Unix systems.
Ok, that sounds good. But which featu…