Skip to content

Instantly share code, notes, and snippets.

View primedime's full-sized avatar

Roy Jossfolk primedime

View GitHub Profile
@primedime
primedime / wp-api-http-request-example.js
Last active February 23, 2018 20:25
Sample code for XMLHttpRequest
function getAllCategories() {
const allCategories = [417, 418, 419, 420, 421, 422]
for (let categories of allCategories) {
let ourRequest = new XMLHttpRequest()
ourRequest.open('GET', 'https://www.orlandoattractions.com/wp-json/wp/v2/posts?categories=' + categories)
ourRequest.onload = () => {
if (ourRequest.status >= 200 && ourRequest.status < 400) {
@primedime
primedime / disney-park-wait-time-hours.js
Last active February 16, 2018 15:33
get wait times and open/close hours for Disney Parks
const disneyMagicKingdom = new Themeparks.Parks.WaltDisneyWorldMagicKingdom();
const epcot = new Themeparks.Parks.WaltDisneyWorldEpcot();
const disneyHollywoodStudios = new Themeparks.Parks.WaltDisneyWorldHollywoodStudios();
const disneyAnimalKingdom = new Themeparks.Parks.WaltDisneyWorldAnimalKingdom();
const universalStudiosFlorida = new Themeparks.Parks.UniversalStudiosFlorida();
const universalIslandsOfAdventure = new Themeparks.Parks.UniversalIslandsOfAdventure();
const universalVolcanoBay = new Themeparks.Parks.UniversalVolcanoBay();
const seaworldOrlando = new Themeparks.Parks.SeaworldOrlando();
function my_template( $template ) {
$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
// check if the page url contains ?id=
if( strpos($url,'?id=') !== false ){
if ( $new_template = locate_template( array( 'page-company-profile.php' ) ) )
return $new_template ;
}
return $template;
}
function loadIP() {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://freegeoip.net/json/', true);
xhr.onload = function() {
const data = JSON.parse(this.response);
const country = data.country_code;
console.log(country);
const europe = ['GB', 'AL', 'AD', 'AT', 'BY', 'BE', 'BA', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FO', 'FI', 'FR', 'DE', 'GI', 'GR', 'HU', 'IS', 'IE', 'IT', 'LV', 'LI', 'LT', 'LU', 'MK', 'MT', 'MD', 'MC', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SM', 'RS', 'SK', 'SI', 'ES', 'SE', 'CH', 'UA', 'VA', 'RS', 'IM', 'RS', 'ME', 'DE'];
const inEU = europe.indexOf(country) !== -1;
@primedime
primedime / redux-quick-example.js
Last active December 27, 2017 17:50
Quick example of how to properly use Redux
/* Create Reducer, which is a function
that produces some amount of state
*/
const reducer = (state = [], action) => {
if (action.type === 'split_string') {
return action.payload.split('');
} else if (action.type === 'add_character') {
// Make a new array
// Take all elements in current State array
// Add action.payload to new State