Trimming Newlines (\n) from NSStrings

Wow, what a lesson in heartache for such a simple little need.

I’m walking an NSDictionary and need to output the results. Not a hard task. No, not at all.

Except that my source data (API call, long story) is prepending all text nodes with a \n. Or it could be the XML to Dictionary code I picked up and threw into the class like there was no tomorrow.

After several lacklustre searches on Google. I found this:

NSString *newString = [oldString stringByTrimmingCharactersInSet:
[NSCharacterSet newlineCharacterSet]];

Pretty simple when you get right down to it, but still, it took me a little while to find the solution.

Bash Attack

Bash is a great unix shell and one I work in everyday whether at the office or at home.

Everyone who uses this shell regularly will tweak it to match their own special quirks.

Here are some of mine.

Directory Aliases:

alias ls='ls --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto'
alias ll='ls -l --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto'
alias la='ls -la --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto'

Up n directories, minimum one:

..() { if [ $1 -ge 0 2> /dev/null ]; then x=$1; else x=1; fi; for (( i = 0; i < $x; i++ )); do cd ..; done;

Current directory size listing:

alias dud='du --max-depth=1 -h'

Watch something:

function w() { watch -dn1 $*; }

Not much, but I hope someone finds them useful.

Blog: Hello World

Here is the skinny:

I am a professional developer in Toronto. I’ve worked on some very high profile sites and some not so high profile.

I’ve been gainfully employed since 1998 as a developer and have seen the best and worst practices, pre-existing code and clients.

This site is a semi-anonymous stage for my thoughts, rants and code-blocks. I won’t critique my current or past employers here but I will give examples of my experiences to help illustrate my points.

I won’t promise that it will be a smooth and eventful ride, but we will arrive at a destination, er, sometime.