Skip to content

Instantly share code, notes, and snippets.

View badfun's full-sized avatar

Ken Dirschl badfun

View GitHub Profile
@badfun
badfun / aws-custom-resource-example.ts
Last active May 27, 2022 21:52
AWS custom resources in the AWS CDK allow us to achieve functionality that might not be available otherwise. In this case, I needed a secure string parameter to be converted to a string that I could pass directly to a bash script. Any of the other lookups resulted in an error, as it would pass either the token itself or the encrypted string.
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from '@aws-cdk/custom-resources'
/**
* Secure string from Parameter store
*/
const getParameter = new AwsCustomResource(this, 'SsmSecureStringParameter', {
onUpdate: {
service: 'SSM',
action: 'getParameter',
parameters: {
@badfun
badfun / aws-backup-stack.ts
Created June 1, 2021 14:35
AWS Backup plan with WindowsVSS and copy to another account enabled
// Backup plan using L1 construct since advanced features not supported at this time
const plan = new CfnBackupPlan(this, 'CriticalResourceBackupPlan', {
backupPlan: {
advancedBackupSettings: [
{
backupOptions: { WindowsVSS: 'enabled' },
resourceType: 'EC2',
},
],
@badfun
badfun / debug_logger.php
Last active November 1, 2016 20:41
Simple debug logger
<?php
/**
* Simple debug logger
*
* @param $data
*/
function ctrial_write_debug_log( $data ) {
$debug_file = 'debug.txt';
// if file already exists append data
@badfun
badfun / load_jquery.php
Last active August 29, 2015 14:26
Sometimes in WordPress, for reasons unknown, jQuery does not get registered or loaded. This function checks if jQuery has been enqueued, and if not, registers and enqueues it.
function bfp_load_jquery_if_not_loading(){
if( ! wp_script_is( 'jquery', 'enqueued') && ! is_admin() ){
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', false, '1.11.3');
wp_enqueue_script('jquery');
}
}
add_action( 'wp_enqueue_scripts', 'bfp_load_jquery_if_not_loading');
@badfun
badfun / get template directory uri shortcode
Last active March 13, 2018 08:22
[template_directory] shortcode allows use of get_template_directory_uri() function in TinyMCE editor WordPress
/**
* Shortcode for WP function get_template_directory_uri();
*/
// Add Shortcode
function bfp_get_template_directory() {
$directory = get_template_directory_uri();
// Code
return $directory;
}
@badfun
badfun / disable autop
Last active December 23, 2015 00:29
Disable autoformatting in TinyMCE editor in WordPress
/**
* Disable autop shortcode for our html pages
*/
function bfp_clean_formatter($content) {
$new_content = '';
$pattern_full = '{(\[clean\].*?\[/clean\])}is';
$pattern_contents = '{\[clean\](.*?)\[/clean\]}is';
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($pieces as $piece) {