old tips | faq | feedback         sign in
Code breakfast
Coding tips for today Sunday 20 May 2012

code

Separate out your exception handling

Say you have a method similar to the following

void DoSomethingAmazing()
{ 
    try
    {
       // do lots of stuff
    }
    catch 
    {
       // handle exception in an amazing way
    }
}

Then you go off happily coding away and you want to...


Read more... by Stephen Stone

language

C#

Format strings

To specify a format string for use with String.Format the following structure is required.

{index[,alignment][:format]}

For example :

String.Format( "One number : {0:#.00####} Another number *{1,10:#}*", 100, 200 ); 
  • { } : the format...


Read more... by Plertrood

Ruby

Create a hash from a list of keys and their mapped values

I always miss creating a Hash using an array of keys and an array of their associated values, like :

Hash[key1, key2], [value1, value2]

Ruby doesn’t like this. Its Hashes are created with an array like :

Hash[key1, value1, key2, value2]

This...


Read more... by Stephen Stone

ObjectiveC

Closures

Blocks are what is known as a closure. What this means is that the code inside the block can access the variables that have been defined outside the the block definition.

As can be seen here :

int x = 3;

void(^block)() = ^() {
...

Read more... by Mac

ide

VisualStudio

Uppercase

Ctrl + Shift + U -> Converts selected text to UPPERCASE

There is no default key combination for converting to lowercase. For this, go through the menus: Edit -> Advanced -> Make Lowercase


Read more... by Plertrood

Vim

Getting into edit mode

When in Command mode, there are a number of keys to get into Insert mode to start entering text.

i -> Insert text before the cursor
I -> Insert text at the beginning of the line
a -> Append text after the cursor
A -> Append text at the...


Read more... by Plertrood

XCode

Page up and Page down

To go up or down a page without the PC Page up and Page down keys use:

fn alt up -> Page up

fn alt down -> Page down


Read more... by Mac