New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets for: Al Gonzalez
To Encrypt, run the following from the Visual Studio command prompt:
 
  aspnet_regiis -pe "connectionStrings" -app "/AppName" -prov "RsaProtectedConfigurationProvider"
 
To Decrypt, run the following from the Visual Studio command prompt:
 
  aspnet_regiis -pd "connectionStrings" -app "/AppName"
 
by Al Gonzalez   July 12, 2010 @ 4:39pm
32 Views
no comments
 
C#
var procs = Process.GetProcessesByName("msnmsgr");
if (procs.Length > 0)
{
    var proc = procs[0];
    proc.Kill();
}
by Al Gonzalez   June 19, 2010 @ 1:05pm
Tags:
31 Views
no comments
 
C#
public static PerpetualEnumerator<T> GetPerpetualEnumerator<T>(this IEnumerable<T> items)
{
    return new PerpetualEnumerator<T>(items);
}
35 Views
no comments
 
C#
using System.Collections;
using System.Collections.Generic;
 
namespace nl4net
{
    /// <summary>
    /// Wraps a standard IEnumerator&lt;T&gt; to provide
    /// iteration over a generic collection that automatically 
    /// resets to the beginning once it reaches the end.
    /// </summary>
by Al Gonzalez   June 17, 2010 @ 9:08pm
28 Views
no comments
 
see http://www.fiddler2.com/fiddler2/
 
NOTE: When using the Visual Studio Developer Web Server you 
      will need to do one of the following: 
1. Call the web services using http://127.0.0.1.:55555/ (note the period after the 1)
2. Add the following to the Fiddler Rules in OnBeforeRequest function,
   remembering to change {machinename} to your computers name
 
    // [CUSTOM] Added to remap call from machine back to localhost
    if (oSession.host=="{machinename}:55555"){
by Al Gonzalez   June 06, 2010 @ 7:15pm
71 Views
no comments
 
C#
public static void Copy(string sourceDirName, string destDirName, bool excludeSubdirectories)
{
    // Style #1: fluent
    Guard.MethodArgument("sourceDirName").IsNotNullOrEmpty(sourceDirName);
    Guard.MethodArgument("destDirName").IsNotNullOrEmpty(destDirName, "The destination directory is required!");
 
    // Style #2: lambdas and expressions
    Guard.Argument.IsNotNullOrWhiteSpace(()=>sourceDirName);
    Guard.Argument.IsNotNullOrWhiteSpace(()=>destDirName, "The destination directory is required!");
by Al Gonzalez   May 24, 2010 @ 8:58pm
67 Views
1 comments
 
C#
public class ConsoleSpinner
{
    const int MaxSegmentIndex = 3;
 
    readonly char[] _segments = new [] {  '\\', '|', '/', '-'};
    readonly int _left;
    readonly int _top;
 
    int _curIndex;
by Al Gonzalez   May 18, 2010 @ 6:43am
116 Views
no comments
 
C#
// Comparing C# to the "Java’s toLowerCase() has got a surprise for you!" article:
// http://javapapers.com/core-java/javas-tolowercase-has-got-a-surprise-for-you/
// ------------------------------------------------------------
// NOTE: C# doesn't seem to exhibit the same issue.
// ------------------------------------------------------------
 
static void Main(string[] args)
{
    // setting Lithuanian as locale 
    System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("lt");
by Al Gonzalez   May 10, 2010 @ 2:18pm
Tags:
35 Views
no comments
 
C#
using System;
using System.Runtime.Serialization;
 
public class ArgumentExceptionTemplate
    : ArgumentException
{
    public ArgumentExceptionTemplate()
    { }
 
    public ArgumentExceptionTemplate(string message)
by Al Gonzalez   April 07, 2010 @ 12:53pm
47 Views
no comments
 
C#
using System;
using System.Runtime.Serialization;
 
public class ExceptionTemplate
    : Exception
{
    public ExceptionTemplate()
    { }
 
    public ExceptionTemplate(string message)
by Al Gonzalez   April 07, 2010 @ 12:48pm
58 Views
no comments
 
C#
/// <summary>
/// Determine if the specified string is blank, where blank is defined 
/// as null, empty or containing only whitespace characters.
/// </summary>
/// <param name="value">string to be evaluated</param>
/// <returns>
/// true if the value is null, empty or contains only 
/// whitespace characters; otherwise false
/// </returns>
static bool IsNullOrWhiteSpace(string value)
by Al Gonzalez   March 15, 2010 @ 11:05am
Tags: String, LINQ, Any
71 Views
no comments
 
C#
/// <summary>
/// Returns a page worth of items from the specified collection.
/// </summary>
/// <typeparam name="TSource">the type of the items in the collection</typeparam>
/// <param name="source">an IEnumerable&gt;TSource&lt; of items to page</param>
/// <param name="pageNumber">the number of the page to return</param>
/// <param name="itemsPerPage">the number of items that make up a page</param>
/// <returns>
/// An IEnumerable&gt;TSource&lt; the contains the specified number of items for the specified pageNumber. 
/// If pageNumber exceeds the number of available pages, the returned collection will be empty.
by Al Gonzalez   March 15, 2010 @ 9:59am
Tags: LINQ, Skip, Take, Paging
66 Views
no comments
 
@echo off
if (%1)==() goto end
if not exist %1 goto createEmpty
:touch
copy /b %1+ > nul
echo %1 was touched!
goto end
:createEmpty
type %1>%1
echo %1 was created!
by Al Gonzalez   February 19, 2010 @ 9:14pm
Tags: Touch, Batch
52 Views
no comments
 
rem Replace {folder} with the folder whose content you want to delete
rem Replace {folderToKeep} with the folder under {folder} you DON'T want to delete
del /F /Q {folder}\*.*
for /D %i in ({folder}\*.*) do if /I NOT (%i)==({folder}\{folderToKeep}) rd /s /q %i
by Al Gonzalez   February 12, 2010 @ 8:05am
Tags:
43 Views
no comments
 
mtsd=for /F "tokens=2,3,4 delims=/ " %i in ('date /t') do set dtName=%k%i%j$Tfor /F "tokens=1,2,3 delims=: " %i in ('time /t') do set dtName=%dtName%_%i%j%k$Tmd %dtName%$Tset dtName=
by Al Gonzalez   February 10, 2010 @ 2:27pm
50 Views
no comments
 
[alias]
# show author and revision number
blame = annotate -u -n
 
# clearer Git style diff output
dif = diff --git
 
log5 = log --limit 5
log10 = log --limit 10
log25 = log --limit 25
by Al Gonzalez   February 05, 2010 @ 8:13am
49 Views
no comments
 
syntax: glob
#-- Files
*.bak.*
*.bak
thumbs.db
*.msi
 
#-- Directories
App_Data/*
bin/
by Al Gonzalez   January 29, 2010 @ 1:40pm
139 Views
no comments
 
@echo off
rem Shell wrapper for Mercurial Distributed SCM
setlocal
rem ########################################
rem NOTES:
rem   /I flag on if forces case-insensitive comparisons for ==
rem ########################################
 
rem ########################################
rem Set the following variables to the 
by Al Gonzalez   January 28, 2010 @ 1:31pm
159 Views
4 comments
 
Sub ToggleMvcBuildViews()
    DTE.ExecuteCommand("Project.UnloadProject")
    DTE.ExecuteCommand("OtherContextMenus.StubProject.EditProjectFile")
 
    Dim wasSetToTrue As Boolean = SetMvcBuildView(True)
    Dim wasSetToFalse As Boolean
    If Not wasSetToTrue Then
        wasSetToFalse = SetMvcBuildView(False)
    End If
by Al Gonzalez   December 08, 2009 @ 9:31pm
179 Views
no comments
 
C#
/// <summary>
/// Writes the text (expression body) of the function being called, followed by its output.
/// </summary>
/// <typeparam name="T">The return type of expression/function.</typeparam>
/// <param name="expression">
/// The expression/function to be evaluated and whose output will be displayed.
/// </param>
/// <remarks>
/// Useful in seeing the results of function calls while debugging or 
/// working on spike solutions (see http://www.extremeprogramming.org/rules/spike.html). 
by Al Gonzalez   July 14, 2009 @ 4:31pm
80 Views
no comments
 
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate