How to Shrink Your Sql Server Log Files#
http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/ Assuming SMS is your database name and sms_log is your transaction log name: USE SMS GO DBCC SHRINKFILE(sms_log, 1) BACKUP LOG sms WITH TRUNCATE_ONLY DBCC SHRINKFILE(sms_log, 1)
Thursday, September 11, 2008 2:48:48 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Find Size of Each Table in Database#
If you need to find the size of each table in the database here is an easy way. EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'" I use it to find those pesky tables that are hogging all my disk space. (Usually it's the log file though) Source: http://www.4guysfromrolla.com/webtech/032906-1.shtml
Thursday, September 11, 2008 2:45:13 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Checking if a value is numeric in C# (isnumber or Isnumeric)#

This method indicates whether an object is numeric or not.  Handy in reflection type situations when you need to perform and action based on type.

private static bool IsNumeric(Object o)
{
    if((o is int) || (o is int?) ||
        (o is decimal) || (o is decimal?) ||
        (o is double) || (o is double?) ||
        (o is float) || (o is float?) ||
        (o is long) || (o is long?) ||
        (o is ulong) || (o is ulong?) ||
        (o is ushort) || (o is ushort?) ||
        (o is short) || (o is short?) ||
        (o is byte) || (o is byte?) ||
        (o is sbyte) || (o is sbyte?) ||
        (o is uint) || (o is uint?))
        
        return true;
    
    return false;
}


It's long and a bit ugly but it's the only way I've found.

Wednesday, July 30, 2008 1:24:38 PM (Central Standard Time, UTC-06:00) #    Comments [1]  | 

 

Type Inference Only Works at the Local Level#
http://erikengbrecht.blogspot.com/2008/07/love-hate-and-type-inference.html

Type inference is great, locally that is.  When it's global it's a mess.  That's why large programs are easier to maintain and refactor in C# than in Python. 

Conversely, scripts are much better in Python than in C#.

So when right a short and dirty script, Python is fantastic.  When writing something a little bigger, the statically typed languages start to win.  There is no "Static is better or Dynamic is better"  only what locally optimal.

I think C# 3.0 is blurring the line somewhat with the best of both worlds.  It's locally type inferred (or it can be if you want it that way) and globally static. 


 | 
Sunday, July 13, 2008 8:06:02 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Web Scraping is Hard Because Sites Are Not Valid#
Scraping the web is hard.

Matt Cutts says so:
http://www.mattcutts.com/blog/the-web-is-a-fuzz-test-patch-your-browser-and-your-web-server/

I've found this to be true.

 A couple of implications. 

It's hard to build a web crawler that can suck information out of pages reliably.

Validation doesn't matter b/c google doesn't penalize for it.  And if Google doesn't care, you shouldn't either.


Sunday, July 13, 2008 7:54:28 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Tips for Robust Software#
  1. Reduce dependencies
    Isolate them if you can't remove them.
  2. Log Don't Explode
  3. Don't Handle Errors if You Don't Know How
    Let them raise so they can get identified and fixed
Tuesday, June 24, 2008 3:49:58 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Humanize String in C# (Split String On Capital Letters)#
Occasionally I need to change a a camel case or Pascal case string into a human readable string.  Since I find myself doing this again and again, I figured I better post it here.


private string HumanizeString(string source)
{
StringBuilder sb = new StringBuilder();

char last = char.MinValue;
foreach (char c in source)
{
if (char.IsLower(last) &&
char.IsUpper(c))
{ sb.Append(' '); }
sb.Append(c);
last = c;
}
return sb.ToString();
}

 | 
Thursday, June 12, 2008 3:47:38 PM (Central Standard Time, UTC-06:00) #    Comments [2]  | 

 

Find controls in a page or another control#
Find controls in a page or another control

List<T> FindControls<T>(Control control) where T : Control
{
List<T> list = new List<T>();

foreach (Control c in control.Controls)
{
if (c is T)
{
Global.LogDebug(c.ID);
list.Add(c as T);
}

list.AddRange(FindControls<T>(c));
}

return list;
}


private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}

foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}

return null;
}


 | 
Wednesday, March 26, 2008 9:35:09 AM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

C# Find Compatible Types#
Find the compatible types in an assembly:

public static Type[] FindCompatibleTypes(Assembly assembly, Type baseType)
{
List<Type> types = new List<Type>();

foreach (Type type in assembly.GetTypes())
{
if (type != baseType && baseType.IsAssignableFrom(type))
types.Add(type);
}

return types.ToArray();
}

Wednesday, March 26, 2008 8:43:39 AM (Central Standard Time, UTC-06:00) #    Comments [1]  | 

 

Programmer Personality Types#
In the last few years, I've come to believe very strongly in personality as a key to understanding yourself and your relationship with others.

I've come across an article that I agree with and have seen work in person:

http://www.softwarebyrob.com/2006/08/20/personality-traits-of-the-best-software-developers/

Personally, I've seen the example of flaky people writing flaky code, where the invere is also true; solid people writing solid code.

Sunday, February 24, 2008 9:43:16 AM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Updated JavaScript String Interpolation (Formatting) Function#
Interpolation is just a fancy word for variable substitutioin in a string.

According to the free dictionary interpolate means:
1. To insert or introduce between other elements or parts.
2.
    a. To insert (material) into a text.

Perl does this very well, other language less so.  Less is a hybrid of the C# method for string formatting.  I find it pretty convenient when creating a lot of dynamic html to insert using that oh so hander innerHTML property.  Remember, innerHTML is usually the fastest way to add dynamic html.

function format(format) {
var params = arguments;
var toReturn = format;

for (var i = 0; i < params.length - 1; i++) {
var rString = '\\$\\{' + (i) + '\\}';
var regex = new RegExp(rString, "g");
toReturn = toReturn.replace(regex, params[i + 1]);
}

return toReturn;
}

Here's the original interpolation function that extended the string object.  I don't really think that extending builtin objects is a great idea unless there is no other way.

Sunday, January 20, 2008 7:46:19 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

All content © 2009, prag
On this page
This site
Calendar
<September 2008>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 1.9.6264.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts