Skip to content

Instantly share code, notes, and snippets.


Doug Vanderweide dougvdotcom

View GitHub Profile
dougvdotcom / await-async.cs
Last active Nov 13, 2015
Demonstration of await and async keywords in c#
View await-async.cs
using System;
using System.Threading.Tasks;
using LinqToTwitter;
using System.Data.SqlClient;
namespace linq2twitter_demo {
public class BaseballGame {
public int Id { get; set; }
public DateTime GameDate { get; set; }
public string HomeTeamName { get; set; }
dougvdotcom / FileRecursion.vb
Created Dec 18, 2015
Code for recursively adding file names to a text file via VB.NET. for details.
View FileRecursion.vb
Imports System.IO
Sub GetAllFiles(strPath As String)
Dim objRoot As New DirectoryInfo(strPath)
Dim objSubDir As DirectoryInfo()
Dim objFile As FileInfo()
If objRoot.Exists Then
'if you don't want this to be recursive, remove this for loop
For Each objSubDir In objRoot.GetDirectories
dougvdotcom / NLogErrorLog.sql
Last active Dec 24, 2015
Table and insert stored procedure for NLog when using SQL Server as a target. See for more info.
View NLogErrorLog.sql
USE [mydatabase]
CREATE TABLE [dbo].[NLogErrorLog] (
dougvdotcom / NLog-sqlserver-storedprocedure.config.xml
Last active Dec 28, 2015
Configuration file for NLog when using SQL Server stored procedures as a target. See for more info.
View NLog-sqlserver-storedprocedure.config.xml
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns=""
xsi:schemaLocation=" NLog.xsd"
dougvdotcom / azure-wp-fix-bad-srcset-urls.php
Last active Jan 4, 2016
PHP to correct bad srcset attribute URLs in Scalable WordPress installs using WordPress 4.4. See for details.
View azure-wp-fix-bad-srcset-urls.php
function azure_fix_invalid_srcset_path( $sources ) {
$storageHost = ""; // change me to be your storage domain
$webHost = ""; // change this to be your website domain
$container = "wp-media"; // change this to be the name of your storage container
$newpath = str_replace( $webHost, $storageHost, $sources['url'] );
return str_replace( "wp-content/uploads/D:homesitewwwroot/wp-content/uploads", $container, $newpath );
dougvdotcom / php_form_validate.php
Last active Apr 29, 2016
Simple server-side validation routine for most PHP forms
View php_form_validate.php
Handling PHP Form Postbacks: Same-Page Validation
Copyright (C) 2016 Doug Vanderweide
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dougvdotcom / transients-complex-queries.php
Created May 14, 2016
WordPress Transients API: Cache complex queries, especially those that are used in several locations
View transients-complex-queries.php
function create_pulldown_transient() {
//movies picker
$output = '';
$output = '<!-- transient created ' . date( 'r' ) . ' -->';
$output .= '<select id="mt-movies-select" class="mt-movies-jump">';
$output .= '<option value="">Pick a movie ...</option>';
$movies = get_posts(
dougvdotcom / transients-api-authenticated-content.php
Last active May 14, 2016
WordPress Transients API: Show content to logged-in users, or otherwise access PHP superglobals
View transients-api-authenticated-content.php
if( current_user_can( 'read' ) ) {
if( false === ( $output = get_transient( 'my-insider-news' ) ) ) {
$blurbs = new WP_Query(
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC',
'tax_query' => array(
dougvdotcom / SetMimePropertiesOnBlob.cs
Created Aug 25, 2016
Set the MIME type for a BLOB already in Azure Storage
View SetMimePropertiesOnBlob.cs
using Microsoft.WindowsAzure.Storage;
using System.IO;
var account = CloudStorageAccount.Parse("YourStorageConnectionString");
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference(GetAzureContainerByFileType(type));
var blob = container.GetBlockBlobReference("myphoto.jpg");
blob.Properties.ContentType = "image/jpeg";
dougvdotcom / SetAzureBlobCorsRule.cs
Created Aug 27, 2016
Set the CORS rules on an Azure Storage account to allow two domains, GET / POST, and cache for one hour
View SetAzureBlobCorsRule.cs
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Shared.Protocol;
public void SetCorsRules() {
var rule = new CorsRule
AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Post,
AllowedOrigins = new List<string>