Skip to content

Instantly share code, notes, and snippets.

Avatar

Doug Vanderweide dougvdotcom

View GitHub Profile
@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";
@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 / 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 / 2-ftp-vms-ilb.azuredeploy.json
Last active Aug 26, 2020
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 / 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"
},
View php_js_calc.php
<?
if(isset($_POST['submit'])) {
//correct the following code for your DB server / Db
//and uncomment the connection code block below
/*
$host = "localhost";
$user = "db_user_name";
$pass = "db_user_password";
$dbname = "database_name";
@dougvdotcom
dougvdotcom / iframe-thumbnail.html
Created Dec 6, 2017
Showing A Larger Image OnClick With JavaScript / DOM Example 2: With IFramed Thumbnails
View iframe-thumbnail.html
<!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">
<!--
Showing A Larger Image From A Thumbnail OnClick Via JavaScript / DOM Revisited
Copyright 2008 Doug Vanderweide, dba Rescue-ME
http://www.dougv.com
Distributed under the Creative Commons Attribution / Share-Alike 2.5 License
http://creativecommons.org/licenses/by-sa/3.0/us/
@dougvdotcom
dougvdotcom / thumbnail.html
Created Dec 6, 2017
Showing A Larger Image OnClick With JavaScript / DOM Example 1: With Thumbnails On Same Page
View thumbnail.html
<!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">
<!--
Showing A Larger Image From A Thumbnail OnClick Via JavaScript / DOM Revisited
Copyright 2008 Doug Vanderweide, dba Rescue-ME
http://www.dougv.com
Distributed under the Creative Commons Attribution / Share-Alike 2.5 License
http://creativecommons.org/licenses/by-sa/3.0/us/