Wednesday, June 4, 2008

Why StringBuilder and not String concatenation?

Reasons:

1. A string is immutable meaning you can't actually change the string.

2. StringBuilder is easy to implement. Using built-in functions such as Append and Insert makes my life easier!


Here's my sample code that uses StringBuilder

by the way, do not forget to include this namespace: System.Text

/*
* must be in this format: 999-999-9999
*/
public string formatPhone(string phone)
{
StringBuilder retVal = new StringBuilder();

char[] charArrayPhone = phone.Trim().ToCharArray();
foreach(char cap in charArrayPhone)
{
if (isCharacterNumeric(cap))
retVal.Append(cap);
}

//must only use the last 10 characters (numbers)
if (retVal.Length>10)
retVal.Remove(0,retVal.Length - 10);

//insert dashes
if (retVal.Length>4)
retVal.Insert(retVal.Length - 4, "-");

//area code is not supplied
if(retVal.Length>8)
retVal.Insert(retVal.Length - 8, "-");

return retVal.ToString();
}

/*
* must be in this format: 99999 or 99999-9999
*/
public string formatZipcode(string zipcode)
{
StringBuilder retVal = new StringBuilder();
char[] charArrayZip = zipcode.Trim().ToCharArray();
foreach (char caz in charArrayZip)
{
if (isCharacterNumeric(caz))
retVal.Append(caz);
}

//must only use the first 9 characters (numbers)
if (retVal.Length > 9)
retVal.Remove(9, retVal.Length - 9);

//insert dash
if (retVal.Length > 5)
retVal.Insert(5, "-");


return retVal.ToString();
}

private bool isCharacterNumeric(char Character)
{
char[] charArrayNumbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
foreach (char can in charArrayNumbers)
{
if (Character == can)
return true;
}
return false;
}

Tuesday, June 3, 2008

Guidelines between CLR and T-SQL

• Use declarative T-SQL SELECT, INSERT, UPDATE, and DELETE statements whenever possible. Procedural and row-based processing should be used only when the logic is not expressible using the declarative language.
• If the procedure is simply a wrapper for declarative T-SQL commands it should be written in T-SQL.
• If the procedure primarily involves forward-only, read-only row navigation through a result set with some processing of each row, using the CLR is likely more efficient.
• If the procedure involves both significant data access and computation, consider separating the procedural code into a CLR portion that calls into a T-SQL procedure to perform data access, or a T-SQL procedure that calls into the CLR to perform computation. Another alternative is to use a single T-SQL batch that includes a set of queries that are executed once from managed code to reduce the number of round trips of submitting T-SQL statements from managed.

Wednesday, May 7, 2008

How-To Reset Palm Device To Factory Default

1. Press and hold the power button, then press the reset button for 5 seconds.
2. Let go of the reset button for 3 seconds while the power button is still pressed.
3. Let go of the power button and wait until you see the message to erase all data.
4. Press "UP" button to successfully hard reset the device.
5. Done!

Wednesday, March 5, 2008

Stream Remote Image

Dim URL As String =
"http://chart.apis.google.com/chart?cht=p3&chd=s:hW&chs=250x100&chl=HelloWorld"

Select Case CInt(Request("id"))
Case 1
URL = "http://chart.apis.google.com/chart?cht=p3&chs=420x180&chd=s:Hellob&chl=OtherRestPlayLocomoteForagingEat"
Case 2
URL = "http://chart.apis.google.com/chart?cht=p&chd=s:Uf9a&chs=350x220&chl=Water%20HoleRocky%20AreaTreesBushes"
Case 3
URL = "http://chart.apis.google.com/chart?cht=bhs&chs=300x200&chd=s:Hell8&chbh=30&chf=bg,s,FFF2CC&chxt=x,y&chxl=0:203040501:OctSepAugJulyJun"
End Select


' Get HTML data
Dim client As WebClient = New WebClient()
Dim b As Byte() = client.DownloadData(URL)


Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
response.Clear()
response.AddHeader("Content-Type", "binary/octet-stream")
response.Flush()
response.BinaryWrite(b)
response.Flush()
response.End()

Monday, March 3, 2008

Android's MapView

Plotting a location using Google Maps and Android

xml layout:
{view class="com.google.android.maps.MapView"android:id="@+id/areamapview"android:layout_width="320px"android:layout_height="280px"/}

java code:

import these:
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MapController;
import com.google.android.maps.Point;

creation:
areaMapView = (MapView)this.findViewById(R.id.areamapview);
areaMapView.toggleSatellite();
Point areaPoint = new Point((int)(41.832846978094*1000000),(int)(-87.83592939376831*1000000));
mc = areaMapView.getController();
mc.animateTo(areaPoint);
mc.zoomTo(16);

Thursday, February 28, 2008

AuthzSVNAccessFile svnaccessfile.txt

#Subversion Configuration Handler

#Repository configuration
DAV svn
SVNListParentPath on
SVNParentPath D:\SVN

AuthName "Subversion repositories"
AuthzSVNAccessFile svnaccessfile.txt

# NT Domain Logins.
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
SSPIDomain
SSPIOfferBasic On

#HTpasswd logins.
Require valid-user




inside svnaccessfile.txt

[groups]
developers = domain\user1,domain\user2

#to allow everyone read access
[/] * = r
#allow all developers complete access
@developers = rw

#allow developers to access their projects
[Project1:/]
@developers = rw

Wednesday, February 27, 2008

No installed service named "Apache2"

When Apache launches, it gives error: No installed service named "Apache2"

For some reason Apache doesn't always install the service. What you need to do is go into command prompt (start > run > type in cmd ) then type in: c:\apache2\bin\apache -k install

Make sure change that path to the location you installed Apache to. That should put the service you need back in.

By the way, I got this info from this site:
http://www.ricocheting.com/server/faq.html