New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets for: Rick Strahl
C#
 
/// <summary>
/// Creates a COM instance from a ProgID. Loads either
/// Exe or DLL servers.
/// </summary>
/// <param name="progId"></param>
/// <returns></returns>
public static object CreateComInstance(string progId)
{
    Type type = Type.GetTypeFromProgID(progId);
by Rick Strahl   January 29, 2010 @ 2:52pm
Tags: COM
13 Views
no comments
 
C#
/// <summary>
/// Turns a string into a typed value generically.
/// Explicitly assigns common types and falls back
/// on using type converters for unhandled types.         
/// 
/// Common uses: 
/// * UI -&gt; to data conversions
/// * Parsers
/// <seealso>Class ReflectionUtils</seealso>
/// </summary>
by Rick Strahl   January 08, 2010 @ 4:21pm
427 Views
no comments
 
C#
static string base36Chars = "0123456789abcdefghijklmnopqrstuvwxyz";
static char[] base36CharArray = base36Chars.ToCharArray();            
 
 
/// <summary>
/// Encodes an integer into a string by mapping to alpha and digits (36 chars)
/// chars are embedded as lower case
/// 
/// Example: 4zx12ss
/// </summary>
by Rick Strahl   December 23, 2009 @ 7:28pm
Tags: Base32
324 Views
no comments
 
function copyToClipboard(e) {
    $('#CodeDisplay').editable();
    $('#_contenteditor')
     .focus()
     .select()
     .keydown(function(e) {
        // capture Ctl-C, Ctl-X, ESC to remove editable
        if (e.which == 99 || e.which == 120 || e.which == 27) {                
            // have to delay so text doesn't go away before copy operation
            setTimeout( function() { $("#CodeDisplay").editable("cleanup") },500);
by Rick Strahl   December 17, 2009 @ 3:40pm
97 Views
no comments
 
************************************************************************
* wwProcess :: GetUrlBasePath
****************************************
***  Function: Method responsible for establishing the base path
***            for this application. 
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION GetUrlBasePath()
by Rick Strahl   December 16, 2009 @ 2:43pm
41 Views
no comments
 
C#
/// <summary>
/// Allows setting of a value in a UrlEncoded string. If the key doesn't exist
/// a new one is set, if it exists it's replaced with the new value.
/// </summary>
/// <param name="urlEncoded">A UrlEncoded string of key value pairs</param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static string SetUrlEncodedKey(string urlEncoded, string key, string value)
{
by Rick Strahl   November 30, 2009 @ 4:07pm
203 Views
no comments
 
#include wconnect.h
 
SET PROCEDURE TO wwXmlState.prg ADDITIVE
 
#IF .F.   && Sample code
CLEAR
oState = CREATEOBJECT("wwXMLState")
 
 
oState.LoadXML(FULLPATH( "test.xml"),.T.)
by Rick Strahl   November 28, 2009 @ 1:46am
Tags: XmlState
155 Views
2 comments
 
C#
/// <summary>
/// A semi-generic Response Filter that allows transformations
/// to be easily hooked up easily via a TransformStream event    
/// </summary>
public class TransformResponseFilter : Stream
{
    /// <summary>
    /// The original stream
    /// </summary>
    Stream _stream;
by Rick Strahl   November 12, 2009 @ 12:14pm
197 Views
no comments
 
C#
/// <summary>
/// Summary description for ResponseFilter.
/// </summary>
public partial class ResponseFilter : System.Web.UI.Page
{
   protected System.Web.UI.HtmlControls.HtmlForm Form1;
   protected System.Web.UI.WebControls.TextBox TextBox1;
 
   protected void Page_Load(object sender, System.EventArgs e)
   {
by Rick Strahl   November 11, 2009 @ 5:19pm
223 Views
no comments
 
    var sel =
        $("#gdEntries>tbody>tr")
                .not(":first-child")  // no header
                .not(":last-child")   // no footer
                .filter(":even")
                .addClass("gridalternate");
 
    // *** Demonstrate simple plugin
    sel.fadeTo(2000,0.30);
by Rick Strahl   November 08, 2009 @ 10:05pm
53 Views
no comments
 
C#
IServiceProvider provider = (IServiceProvider)HttpContext.Current.Context;
HttpWorkerRequest worker = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest)); 
 
by Rick Strahl   November 08, 2009 @ 4:26pm
44 Views
no comments
 
C#
/// <summary>
/// Returns an application Url that's Theme relative.
/// images/users.gif
/// returns: /myapp/app_themes/{activetheme}/images/users.gif
/// </summary>
public static string ResolveThemeUrl(string themeRelativePath)
{
    string theme = null;
    
    // try to pick up active theme
by Rick Strahl   October 29, 2009 @ 2:04am
44 Views
no comments
 
C#
 
   public class ListUtils
   {
       /// <summary>
       /// Manual ComboBox binding and adding a first item
       /// 
       /// Assumes you're binding to an enumerable list of some sort
       /// and you're binding to Properties (not fields)
       /// </summary>
       public static void BindWithFirstItem(IEnumerable items, ComboBox listBox,
by Rick Strahl   October 27, 2009 @ 3:46pm
210 Views
1 comments
 
<div class="toolbarcontainer">
    <a href="./" class="hoverbutton"><img src="css/images/home.gif" /> Home</a> | 
    <a href="«Link(Page Name)».aspx"><img src="css/images/refresh.gif" /> Refresh Page</a>
</div>
 
<ww:ErrorDisplay runat="server" id="ErrorDisplay" />
 
<div class="containercontent">
«Marker»
</div>
by Rick Strahl   October 09, 2009 @ 3:12am
Tags:
54 Views
no comments
 
C#
// works as expected
public wws_Item LoadBySku(string sku)
{
    Expression< Func<wws_Item, bool> > func = itm => itm.Sku == sku;
 
    Entity = Context.wws_Items.Where(func).SingleOrDefault();
    if (Entity != null)
        OnLoaded(Entity);
 
    return this.Entity;
by Rick Strahl   October 04, 2009 @ 5:02pm
174 Views
no comments
 
<%@Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="../westwind.css" />
    <title>Web Connection Adminstration</title>
    <style type="text/css">
    .containercontent
    {
        padding: 10px;
by Rick Strahl   September 28, 2009 @ 1:32pm
171 Views
no comments
 
C#
 StockContext context = new StockContext();
 User user = context.Users.Where( uss => uss.Pk == 1).SingleOrDefault();
 Response.Write(user.FullName + "<br>"); 
 user.FullName = user.FullName + "!";
 
 
 StockContext context2 = new StockContext();
 User user2 = context.Users.Where(uss => uss.Pk == 1).SingleOrDefault();
 Response.Write(user2.FullName + "<br>");
 user2.FullName = user2.FullName + "!";
by Rick Strahl   September 27, 2009 @ 2:34pm
78 Views
no comments
 
C#
public void LogSnippetViewAsync(string snippetId, string ipAddress, string userAgent)
{
    Func<string, string, string, bool> del = this.LogSnippetView; 
    del.BeginInvoke(snippetId, ipAddress,userAgent,null,null);            
}
 
public bool LogSnippetView(string snippetId, string ipAddress, string userAgent)
{
    if (string.IsNullOrEmpty(userAgent))
        return false;
by Rick Strahl   September 24, 2009 @ 3:31pm
175 Views
no comments
 
C#
public class SecurityUtils
{
 
    const int LOGON32_LOGON_INTERACTIVE = 2;
    const int LOGON32_LOGON_NETWORK = 3;
    const int LOGON32_LOGON_BATCH = 4;
    const int LOGON32_LOGON_SERVICE = 5;
    const int LOGON32_LOGON_UNLOCK = 7;
    const int LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
    const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
by Rick Strahl   September 23, 2009 @ 5:34pm
78 Views
no comments
 
C#
private void GetResourceSet()
{
    this.ResourceSet = Request.Form[this.lstResourceSet.UniqueID];
    if (ResourceSet == null)
        this.ResourceSet = Request.QueryString["ResourceSet"];
    if (this.ResourceSet == null)
        this.ResourceSet = ViewState["ResourceSet"] as string;
 
    if (this.ResourceSet == null)
        this.ResourceSet = "";
by Rick Strahl   September 22, 2009 @ 1:17pm
182 Views
no comments
 
if (JSON && !JSON.parseWithDate) {
    var reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/;
    var reMsAjax = /^\/Date\((d|-|.*)\)[\/|\\]$/;
 
    JSON.parseWithDate = function(json) {
        /// <summary>
        /// parses a JSON string and turns ISO or MSAJAX date strings
        /// into native JS date objects
        /// </summary>    
        /// <param name="json" type="var">json with dates to parse</param>        
by Rick Strahl   September 15, 2009 @ 3:31pm
165 Views
no comments
 
C#
[TestClass]
public class DateConversionTests
{
    public DateConversionTests()
    {
    }        
 
 
    [TestMethod]
    public void AjaxDate_IsoDate_DataContract_DeserializationTest()
by Rick Strahl   September 15, 2009 @ 12:46pm
221 Views
no comments
 
CSS
.smallprogress,.smallprogressright
{
    width: 16px;
    height: 16px;
    background-image: url(images/loading_small.gif);
    background-repeat: no-repeat;        
    display: inline-block;    
    xdisplay: none;    
}
.smallprogressright { float: right }
by Rick Strahl   September 14, 2009 @ 2:21pm
90 Views
no comments
 
error: function(xhr, status) {                   
    var err = null;
    if (xhr.readyState == 4) {
        var res = xhr.responseText;
 
        if (res && res.substr(0,1) == '{')
            var err = JSON.parseWithDate(res);
        if (!err) {
            if (xhr.status && xhr.status != 200)
                err = new CallbackException(xhr.status + " " + xhr.statusText);
by Rick Strahl   September 11, 2009 @ 6:43pm
145 Views
no comments
 
C#
public static string GetFullApplicationPath()
{
    var url = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);            
    return url + HttpContext.Current.Request.ApplicationPath.TrimEnd('/');
}
by Rick Strahl   September 07, 2009 @ 3:56pm
74 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