Error
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.

method

How to Sort an Arrays of primitive types
Friday, 23 December 2011 00:21
To sort array of primitive types such as int, double or string use method Array.Sort(Array) with the array as a paramater. The primitive types implements interface IComparable, which is internally used by the Sort method (it calls IComparable.ComĀ­pareTo method). See example how to sort int array:


// sort int array
int[] intArray = new int[5] { 8, 10, 2, 6, 3 };
Array.Sort(intArray);
// write array
foreach (int i in intArray) Console.Write(i + " ");

//OUTPUT
2 3 6 8 10

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/XAjB9RinXZI/14309

 
Cool use of String.Format method
Wednesday, 14 December 2011 02:05
The string.Format method is a static method that receives a string that specifies where the following arguments should be inserted, and these are called substitutions

Following example shows the use of the string.Format method to combine three strings with formatting options. The format string itself is the first argument to the string.Format method and it is specified as a string literal.

The position markers in the format string are specified to the left of the colons, and this means the "0", "1:", and "2:" indicate where the first, second, and third arguments are inserted. The part after the ":" and in between the { } brackets indicates the exact format specification for that variable.

String Literal

static void Main()
{
//
// Declare three variables that we will use in the format method.
// ... The values they have are not important.
//
string value1 = "This is test";
int value2 = 530;
DateTime value3 = new DateTime(2011, 11, 11);
//
// Use string.Format method with four arguments.
// ... The first argument is the formatting string.
// ... It specifies how the next three arguments are formatted.
//
string result = string.Format("{0}: {1:0.0} - {2:yyyy}",value1,value2,value3);
Console.WriteLine(result);
}
/*
OUTPUT
This is test: 530.0 - 2011
*/


Number formats
You can specify that a value type such as a double can be formatted inside the string.Format method based on the format string. The format string is the first argument to the string.Format method. The format string in this example uses the 0:0.0% syntax, which means that the second argument should be formatted with the pattern 0.0%. The arguments are numbered starting at zero.

static void Main()
{
//
// Format a ratio as a percentage string.
// ... You must specify the percentage symbol in the format string.
// ... It will multiply the value by 100 for you.
//
double ratio = 0.530;
string result = string.Format("string = {0:0.0%}",ratio);
Console.WriteLine(result);
}
/*
OUTPUT
string = 530.0%
*/


Padding (PadLeft and PadRight)
Padding can be used with strings in the C# language and this can be expressed declaratively in formatting strings and the string.Format method. The term 'padding' indicates that you are inserting a variable number of characters at the left or right of the string to ensure that the total length of the string is a fixed length. Instead of the PadLeft and PadRight methods, you can use the string.Format method with special substitutions.

static void Main()
{
//
// The constant formatting string.
// ... It specifies the padding.
// ... A negative number means to left-align.
// ... A positive number means to right-align.
//
const string format = "{0,-10} {1,10}";
//
// Construct the strings.
//
string line1 = string.Format(format,100,5);
string line2 = string.Format(format,"Carrot","Giraffe");
Console.WriteLine(line1);
Console.WriteLine(line2);
}
/*
OUTPUT
100 5
Carrot Giraffe
*/


ToString or string.Format
Sometimes, you need to just format a single number, like an integer or long. In this case, you don't need to use string.Format. You can just use the ToString virtual method.

static void Main()
{
int value = 123;
string a = string.Format("{0:0000}", value); // Too complex
string b = value.ToString("0000"); // Simpler
Console.WriteLine(a);
Console.WriteLine(b);
}
/*
OUTPUT
0123
0123
*/


DateTime Format
format string pattern defined as followse
MMM display three-letter month
ddd display three-letter day of the WEEK
d display day of the MONTH
HH display two-digit hours on 24-hour scale
mm display two-digit minutes
yyyy display four-digit year


static void Main()
{
DateTime time = DateTime.Now; // Use current time
string format = "MMM ddd d HH:mm yyyy"; // Use this format
Console.WriteLine(time.ToString(format)); // Write to console
}
/*
OUTPUT
Feb Fri 27 11:41 2009
*/

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/DUa-Zy493Oo/14175

 
Saving objects in redis and php
Wednesday, 07 December 2011 06:08
// A fairly generic method to store arrays and also to add them to a pool to reverse lookup their ids based on values that they contain. This method extends my own redis client but will work for the better clients out there such as predis.


class storage extends redis {

public function save($key, array $object, $timestamp=true){
$timestamp && $object['timestamp'] = date('Ymdhis');
$id = $this->incr('id:'.$key);

foreach ($object as $k => $v) {
$this->sadd(sprintf("%s:%s:%s", $key, $k, $v), $id);
}

$key = sprintf("%s:%s", $key, $id);
$this->hmset($key, $object);
}
}

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/iWN17GMGOoI/14089

 
Combat Cavities By Re-Growing Your Decaying Teeth [Science]
Wednesday, 24 August 2011 00:40
A team of researchers at the University of Leeds' School of Chemistry is developing a pain-free method to combat cavities. More »


Read more: http://feeds.gawker.com/~r/gizmodo/full/~3/Dn5PDxcIIyc/combat-cavities-by-re+growing-your-decaying-teeth

 
How To Do A CentOS 6.0 Network Installation (Over HTTP)
Friday, 15 July 2011 07:43

How To Do A CentOS 6.0 Network Installation (Over HTTP)

This tutorial shows the process of installing CentOS 6.0 using the HTTP NetInstall method. This method is much faster for basic systems since you don't have to download ISO files or one huge DVD based ISO just to get started. If you are installing many systems you may want to look into the stand-alone DVD as it will save time in the end.

Read more: http://howtoforge.com/how-to-do-a-centos-6.0-network-installation-over-http

 
Start
Prev
1


Page 1 of 2
Taxonomy by Zaragoza Online