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 / 2-ftp-vms-ilb.azuredeploy.parameters.json
Last active Mar 31, 2019
parameters file for 2-ftp-vms-ilb.azuredeploy.json
View 2-ftp-vms-ilb.azuredeploy.parameters.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"value": "dvftpstorage"
},
"adminUsername": {
"value": "dvroot"
},
@dougvdotcom
dougvdotcom / 2-ftp-vms-ilb.azuredeploy.json
Last active May 22, 2019
Create two Azure VMs in an availability set, with an internal load balancer, with PASV FTP ports enabled
View 2-ftp-vms-ilb.azuredeploy.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string",
"metadata": {
"description": "Name of storage account"
}
},
@dougvdotcom
dougvdotcom / AzureBatchSetCacheControl.cs
Last active Sep 10, 2016
Loops through all containers and blobs in an Azure Storage account; sets cache-control header on all public CloudBlockBlob objects found.
View AzureBatchSetCacheControl.cs
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
namespace AzureCDN
{
class Program
{
static void Main()
{
@dougvdotcom
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>
{
@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";
@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 / 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 / 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(
@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 / 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.
You can’t perform that action at this time.