Skip to content

Instantly share code, notes, and snippets.

@BHWD
BHWD / json-structure-format.html
Created June 27, 2017 08:37
Show JSON structure in formated list
function process_test_json() {
var jsonDataArr = { "Errors":[],"Success":true,"Data":{"step0":{"collectionNameStr":"dei_ideas_org_Private","url_root":"http:\/\/192.168.1.128:8500\/dei-ideas_org\/","collectionPathStr":"C:\\ColdFusion8\\wwwroot\\dei-ideas_org\\wwwrootchapter0-2\\verity_collections\\","writeVerityLastFileNameStr":"C:\\ColdFusion8\\wwwroot\\dei-ideas_org\\wwwroot\\chapter0-2\\VerityLastFileName.txt","doneFlag":false,"state_dbrec":{},"errorMsgStr":"","fileroot":"C:\\ColdFusion8\\wwwroot\\dei-ideas_org\\wwwroot"}}};
var htmlStr= "<h3 class='recurse_title'>[jsonDataArr] struct is</h3> " + recurse( jsonDataArr );
alert( htmlStr );
$( document.createElement('div') ).attr( "class", "main_div").html( htmlStr ).appendTo('div#out');
$("div#outAsHtml").text( $("div#out").html() );
}
function recurse( data ) {
var htmlRetStr = "<ul class='recurseObj' >";
// Get the height of the header
var headerHeight = jQuery(".navbar-fixed-top").height();
// Attach the click event
jQuery('a[href*=#]').bind("click", function(e) {
e.preventDefault();
var target = jQuery(this).attr("href"); //Get the target
var scrollToPosition = jQuery(target).offset().top - headerHeight;
<style>
.popup {
width:100%;
position:fixed;
z-index:99999999;
bottom:0px;
left: 50%;
transform: translateX(-50%);
text-align:center;
font-family: Open Sans;
ALTER TABLE `[table name]`
ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY (`id`);
@BHWD
BHWD / redirect-user-ip.php
Created May 17, 2017 11:31
Redirect users based on IP. USeful for hiding websites from clients
<?php
$visitor = $_SERVER['REMOTE_ADDR'];
if (preg_match("/192.168.0.1/",$visitor)) {
header('Location: http://www.yoursite.com/thank-you.html');
} else {
header('Location: http://www.yoursite.com/home-page.html');
};
?>
<?php
/*
Plugin Name: Your Plugin's Name
Plugin URI: http://plugin-homepage
Description: A description of your plugin.
Version: 0.1
Author: Your Name
Author URI: http://author-homepage
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
<?php
/* hex to rgba - place in functions.php */
function hexToRgb($hex, $alpha = false) {
$hex = str_replace('#', '', $hex);
$length = strlen($hex);
$rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
$rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
$rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
if ( $alpha ) {
$rgb['a'] = $alpha;
//remove wordpress authentication
remove_filter('authenticate', 'wp_authenticate_username_password', 20);
add_filter('authenticate', function($user, $email, $password){
//Check for empty fields
if(empty($email) || empty ($password)){
//create new error object and add errors to it.
$error = new WP_Error();
<?php
/***
* Change Hex to RGBA
* Change the number after each variable for each usage
* Change the sub_field ID each time.
* use 'echo $color*' for Hex
* use 'echo $rgba*' for RGBA
***/
$color1 = the_sub_field( 'pe_5050_image_grid_title_background_colour' );
$rgba1 = hex2rgba($color1, 0.82);