Skip to content

Instantly share code, notes, and snippets.

Doug Vanderweide dougvdotcom

Block or report user

Report or block dougvdotcom

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dougvdotcom
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
dougvdotcom / twitter-character-count.cs
Last active Nov 9, 2017
Demonstrates how to count characters in .NET for Twitter status updates
View twitter-character-count.cs
using System;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
namespace TwitterWordCount
{
class Program
{
static void Main()
@dougvdotcom
dougvdotcom / FileRecursion.vb
Created Dec 18, 2015
Code for recursively adding file names to a text file via VB.NET. http://dougv.us/r5 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
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 http://dougv.us/r6 for more info.
View NLog-sqlserver-storedprocedure.config.xml
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off">
<targets>
<target
xsi:type="Database"
@dougvdotcom
dougvdotcom / NLogErrorLog.sql
Last active Dec 24, 2015
Table and insert stored procedure for NLog when using SQL Server as a target. See http://dougv.us/r6 for more info.
View NLogErrorLog.sql
USE [mydatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NLogErrorLog] (
@dougvdotcom
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 http://dougv.us/r7 for details.
View azure-wp-fix-bad-srcset-urls.php
<?php
function azure_fix_invalid_srcset_path( $sources ) {
$storageHost = "xxx.blob.core.windows.net"; // change me to be your storage domain
$webHost = "yyy.azurewebsites.net"; // 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
dougvdotcom / windows-azure-storage.php
Last active Oct 15, 2018
WordPress plugin to fix responsive images, credit Project Nami. Adapted to conform to WordPress coding standards.
View windows-azure-storage.php
<?php
/*
Plugin Name: Azure WordPress Storage Responsive Images Fix
Plugin URI: http://projectnami.org/fix-for-azure-storage-plugin-and-wp-4-4/
Description: Corrects srcset URLs for responsive images in a Scalable WordPress install running on Microsoft Azure.
Author: Project Nami / Doug Vanderweide
Version: 0.1
Author URI: https://www.dougv.com/2016/01/fixing-wordpress-4-4-responsive-images-in-azure-scalable-wordpress-installs/
License: GNU GPL 2
*/
@dougvdotcom
dougvdotcom / php_form_validate.php
Last active Apr 29, 2016
Simple server-side validation routine for most PHP forms
View php_form_validate.php
<?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
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
<?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
dougvdotcom / transients-api-selective-cache.php
Created May 14, 2016
WordPress Transients API, code to expire parts of a web page cache at different times
View transients-api-selective-cache.php
<?php
//get all asides that are in the category music-gigs
if( false === ( $output = get_transient( 'my-gig-asides-list' ) ) ) {
//rebuild transient
$gigs = new WP_Query( array(
'post_status' => 'publish',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC',
'tax_query' => array(
You can’t perform that action at this time.