Skip to content

Instantly share code, notes, and snippets.

@djp424
djp424 / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@djp424
djp424 / create-cat-based-on-cpt.php
Created October 13, 2015 14:54
Creates categories based on cpt (parent posts only) with WordPress
<?php
// creates categories based on cpt (parent posts only)
function create_categories_based_on_ctp() {
// cpt you are coping posts from
$cccpt_posts = array( 'post_type' => 'ctp', 'posts_per_page' => -1 );
$cccpt_postslist = get_posts( $cccpt_posts );
// cpt you are adding categories to
$cccpt_cpt_destination = ''; // example: 'communites'
$cccpt_cpt_description_description = ''; // example: 'this is for communities'
function init() {
if (site_config('agentactivation')) {
add_action('init',array(&$this,'create_post_type'));
//add_action('init',array(&$this,'create_taxonomy'));
//add_filter('post_type_link',array(&$this,'filter_post_link'),10,2);
if (is_admin()) $this->admin_init();
else $this->public_init();
}
}
@djp424
djp424 / urlJsonFetcher.js
Last active August 15, 2018 03:39
Fetch and append JSON data from list of URLs (in order just in case some of the requests are large)
// Get's list of urls, grabs the title in json, and appends them to a selector of your choice
function requester(urls, selector) {
if(urls === undefined || urls.length === 0) {
return;
}
var request = new XMLHttpRequest();
request.open('GET', urls[0]);
request.responseType = 'json';
@djp424
djp424 / urlJsonFetcherAsyncXML.js
Last active August 20, 2018 18:37
Asynchronous fetch JSON data from URLs with Promises (XMLHttpRequest)
// Get data from list of URL's in asynchronous.
function asyncRequester(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = () => resolve(xhr.responseText);
xhr.onerror = () => reject(xhr.statusText);
xhr.send();
});
@djp424
djp424 / urlJsonFetcherAsyncFetch.js
Created August 20, 2018 18:38
Asynchronous fetch JSON data from URLs with Promises (Fetch)
// Get data from list of URL's in asynchronous.
function asyncRequester(url) {
return fetch(url).then((response) => response.json());
}
var urls = ['temp.json', 'temp.json', 'temp.json', 'temp.json', 'temp.json'],
pall = [],
resu = document.querySelector('#results');
def printCharPermutations(word):
print('') # 0
if len(word) == 1: # 1
print(word[0])
return
printCharPermutationsHelper('', word, len(word))
def printCharPermutationsHelper(currentPermutation, lettersICanUse, maxLen): # 3.
@djp424
djp424 / wp-config-mutisite-debug.php
Created October 20, 2014 14:20
How to turn WordPress Debug on for a single site in a MultiSite Install. From https://wordpress.org/support/topic/debugging-multisite-blogs put this in wp-config.php
if ($_SERVER['HTTP_HOST']=='site1.example.com')
define('WP_DEBUG', true);
else
define('WP_DEBUG', false);
@djp424
djp424 / index.test.js
Created July 21, 2021 23:36
addPositiveNumbers Jest tests
import { addPositiveNumbers } from '../index';
import * as IsPositiveNumber from "../isPositiveNumber";
IsPositiveNumber.isPositiveNumber = jest.fn();
describe('addPositiveNumbers', () => {
afterEach(() => {
jest.clearAllMocks();
});
@djp424
djp424 / index.test.js
Last active August 16, 2021 18:17
JS testing workshop solutions
import { add } from '../index';
import { addPositiveNumbers } from '../index';
import { addListItem} from '../index';
import { commaSeparatedStringToArray } from '../index';
import * as IsPositiveNumber from "../isPositiveNumber";
import { latestRollingStoneArticleTitle } from '../index';
IsPositiveNumber.isPositiveNumber = jest.fn();
describe('add', () => {