Skip to content

Instantly share code, notes, and snippets.

Alex McCabe alexmccabe

  • Kerve Creative
  • Bristol
Block or report user

Report or block alexmccabe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alexmccabe
alexmccabe / markerclusterer.js
Created Apr 25, 2019
Fix Google Maps markerclusterer on mobile devices when pinching clusters
View markerclusterer.js
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @externs_url http://closure-compiler.googlecode.com/svn/trunk/contrib/externs/maps/google_maps_api_v3_3.js
// ==/ClosureCompiler==
/**
* @name MarkerClusterer for Google Maps v3
* @version version 1.0.3
* @author Luke Mahe
* @fileoverview
@alexmccabe
alexmccabe / wpml_get_languages.php
Created Oct 11, 2018
WPML will return all languages for the current page, even if they are in draft mode. This is not right. This horrible work around solves that issue.
View wpml_get_languages.php
function wpml_get_languages ($options = 'skip_missing=1&orderby=code&order=desc') {
$languages = icl_get_languages($options);
$currentID = get_queried_object_id();
foreach ($languages as $key => $language) {
$id = icl_object_id($currentID, 'page', false, $language['language_code']);
$status = get_post_status($id);
if ($status !== 'publish') {
View getSiblings.js
const getSiblings = (element) => {
return Array.prototype
.slice
.call(element.parentNode.children)
.filter(item => item !== element);
}
@alexmccabe
alexmccabe / better_get_template_part.php
Last active Sep 11, 2018
After getting incredibly frustrated with the included get_template_part function in Wordpress, I decided to write my own that makes getting templates much easier. This function allows you to omit the '.php' extension, and also pass down data to the included file. You can just add this anywhere in your `functions.php` file, or anywhere else that …
View better_get_template_part.php
<?php
if (! function_exists('better_get_template_part') {
/**
* A better way of getting a Wordpress Template Part.
* This function allows you to to omit the '.php' extension, and also pass
* data to the included file.
*
* The data in the array is extracted into variables for use on the
View so-many-options.js
drawText(text, options) {
const context = this.context;
const { baseline, color, font, position, stroke } = options;
if (!text.length || text.constructor !== String) {
throw new Error(
'Text must be a string with at least one character'
);
}
View isInViewport.js
export default function (element, threshold) {
threshold = threshold || 0;
var elementTop = element.offsetTop;
var elementBottom = elementTop + element.clientHeight;
var viewportTop = window.scrollY;
var viewportBottom = viewportTop + window.innerHeight;
return elementBottom > viewportTop && elementTop < viewportBottom;
},
View scrollIntoView.js
function scrollIntoView($element) {
var scrollTop = 0;
if ($element.length) {
scrollTop = $element.offset().top -
$('#headerwrap')[0].clientHeight - 40;
window.scrollTo(0, scrollTop);
}
}
View Array.prototype.map.js
const temp = cityData.list.map(item => item.main.temp);
const humidity = cityData.list.map(item => item.main.humidity);
const pressure = cityData.list.map(item => item.main.pressure);
View Array.prototype.reduce().js
const { temp, pressure, humidity } = cityData.list.reduce(
(current, item) => {
current.temp.push(item.main.temp);
current.pressure.push(item.main.pressure);
current.humidity.push(item.main.humidity);
return current;
},
{ temp: [], pressure: [], humidity: [] }
);
View thing.js
var animate, camera, clock, composer, elapsedTime, frameCount, init, light, loadModel, maskScene, mesh1, mesh2, mesh3, onWindowResize, outScene, render, renderTarget, renderer, scene, screenHeight, screenWidth, setModel, shader, updateFps;
screenWidth = window.innerWidth;
screenHeight = window.innerHeight;
clock = new THREE.Clock();
elapsedTime = 0;
frameCount = 0;
init = function() {
You can’t perform that action at this time.