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 / 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 / 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 / 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 / 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 / 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-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
<?php
if( current_user_can( 'read' ) ) {
if( false === ( $output = get_transient( 'my-insider-news' ) ) ) {
$blurbs = new WP_Query(
array(
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC',
'tax_query' => array(
@dougvdotcom
dougvdotcom / UploadBlobWithMimeType.cs
Created Aug 25, 2016
Upload a BLOB to Azure Storage with a MIME type
View UploadBlobWithMimeType.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
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";
You can’t perform that action at this time.