Blog Archives

vimrc settings

Located in ~/.vimrc

If it doesn’t exist, create it!

set smartindent
set tabstop=2
set shiftwidth=2
set expandtab

"enables mouse in all modes. supports click and scrollwheel. use shift+ins to paste from clipboard
set mouse=a

"for use with pathogen
syntax enable
filetype plugin indent on

"for use with solarized. may require export TERM=xterm-256color
set background=dark
colorscheme solarized

To see more info on these settings, from within vim:

:help smartindent

To format a file with mixed tabs and spaces, after applying the above settings, from within vim:


Concatenate string in Objective-C

Unfortunately, this is not as straight forward as it seems it should be. This really comes down to roughly two approaches in my opinion:

stringByAppendingString approach:

NSString *robot= @"Ronnie";
NSString *robotname = [robot stringByAppendingString:@" is the name of a robot."];

strigWithFormat approach:

NSString *robot= @"Ronnie";
NSString *robotname= @" is the name of the a robot.";
NSString *robotknowledge = @" knows eight languages.";
[NSString stringWithFormat:@"%@/%@/%@", robot, robotname, robot, robotknowledge];

StackOverflow,, “Learn Objective-C”,

PHP Quick Reference

Escape sequences for print output:

\" - double quote
\' - single quote
\n - new line
\t - tab
\r - carriage return
\$ - dollar sign
\\ - backslash

Max integer and float size (overflow):

//on a 32-bit system
$large_number = 2147483647;
var_dump($large_number);                     // int(2147483647)

$large_number = 2147483648;
var_dump($large_number);                     // float(2147483648)

$million = 1000000;
$large_number =  50000 * $million;
var_dump($large_number);                     // float(50000000000)

//on a 64-bit system
$large_number = 9223372036854775807;
var_dump($large_number);                     // int(9223372036854775807)

$large_number = 9223372036854775808;
var_dump($large_number);                     // float(9.2233720368548E+18)

$million = 1000000;
$large_number =  50000000000000 * $million;
var_dump($large_number);                     // float(5.0E+19)

generate random number:

echo rand() . "\n";
echo rand() . "\n";

echo rand(5, 15);

Get Current Page Name:

function curPageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);

Came across the following on stackoverflow while looking for the PHP equivalent of string.format.

Sprintf (similar to php printf, in c# string.format):

$filter = "content:%1$s title:%1$s^4.0 path.title:%1$s^4.0 description:%1$s ...";
$filter = sprintf($filter, "Cheese");


function format() {
    $args = func_get_args();
    if (count($args) == 0) {
    if (count($args) == 1) {
        return $args[0];
    $str = array_shift($args);
    $str = preg_replace_callback('/\\{(0|[1-9]\\d*)\\}/', create_function('$match', '$args = '.var_export($args, true).'; return isset($args[$match[1]]) ? $args[$match[1]] : $match[0];'), $str);
    return $str;

StackOverflow, “C# String.Format() Equivalent in PHP?”,

String Formatting

Snippets below have been condensed from their original sources for brevity. See references for original articles.

All examples are in C# .Net.

My own little function:

   private string DynamicFormat(string dbformatstring, string contentstring)
            foreach (string item in dbformatstring.Split(',')) {
            string propname = item.Split(':')[0];
                string propvalue = item.Split(':')[1];
                contentstring = contentstring.Replace("{"+propname+"}",propvalue);

            return contentstring;

Format With extension method by James Newton-King:

public static string FormatWith(this string format, params object[] args)
  if (format == null)
    throw new ArgumentNullException("format");
  return string.Format(format, args);
public static string FormatWith(this string format, IFormatProvider provider, params object[] args)
  if (format == null)
    throw new ArgumentNullException("format");
  return string.Format(provider, format, args);

James Newton-King, “FormatWith”,