Skip to content

Instantly share code, notes, and snippets.

@djp424
djp424 / index.test.js
Last active Aug 16, 2021
JS testing workshop solutions
View index.test.js
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', () => {
@djp424
djp424 / index.test.js
Created Jul 21, 2021
addPositiveNumbers Jest tests
View index.test.js
import { addPositiveNumbers } from '../index';
import * as IsPositiveNumber from "../isPositiveNumber";
IsPositiveNumber.isPositiveNumber = jest.fn();
describe('addPositiveNumbers', () => {
afterEach(() => {
jest.clearAllMocks();
});
View char-permutations.py
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 / urlJsonFetcherAsyncFetch.js
Created Aug 20, 2018
Asynchronous fetch JSON data from URLs with Promises (Fetch)
View urlJsonFetcherAsyncFetch.js
// 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');
@djp424
djp424 / urlJsonFetcherAsyncXML.js
Last active Aug 20, 2018
Asynchronous fetch JSON data from URLs with Promises (XMLHttpRequest)
View urlJsonFetcherAsyncXML.js
// 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 / urlJsonFetcher.js
Last active Aug 15, 2018
Fetch and append JSON data from list of URLs (in order just in case some of the requests are large)
View urlJsonFetcher.js
// 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 / create-cat-based-on-cpt.php
Created Oct 13, 2015
Creates categories based on cpt (parent posts only) with WordPress
View create-cat-based-on-cpt.php
<?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'
@djp424
djp424 / wp-config-mutisite-debug.php
Created Oct 20, 2014
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
View wp-config-mutisite-debug.php
if ($_SERVER['HTTP_HOST']=='site1.example.com')
define('WP_DEBUG', true);
else
define('WP_DEBUG', false);
@djp424
djp424 / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View gist:6010020
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();
}
}