Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View alexmccabe's full-sized avatar

Alex McCabe alexmccabe

View GitHub Profile
import React, { FunctionComponent, useEffect, useRef, useState } from "react";
import { Animated, StyleSheet, ViewStyle } from "react-native";
interface PropTypes {
duration?: number;
isVisible?: boolean;
style?: ViewStyle | Array<ViewStyle>;
}
/**
@alexmccabe
alexmccabe / createFormData.js
Created June 17, 2020 09:03
Convert object data into FormData
function createFormData(data, previousKey, formData = new FormData()) {
if (isPlainObject(data)) {
Object.keys(data).forEach(key => {
const value = data[key];
let newKey = key;
if (isPlainObject(value)) {
return createFormData(value, key, formData);
}
/**
* Set up the Create Account Form
*
* 1. So this complicated mess is because the connect() function doesn't
* support forwardRef(). The trick is to create a new "connected" version of
* our base component.
*
* 2. And then create the exported version which is wrapped in the forwardRef()
* and given a displayName. This stops the linters from failing and allows
* forwarding of refs.
import React, { useCallback, useState } from 'react';
const FormContext = React.createContext({
getInputValue: (name, defaultValue = '') => null,
onInputChange: name => e => {}
});
function validate(data, rules) {
// validate here
}
import React, { useCallback, useContext, useState } from 'react';
import { connect } from 'react-redux';
import { updateSomeAPIValue } from 'state/APIValue';
const FormContext = React.createContext({
getInputValue: (name, defaultValue = '') => null,
inputChange: name => e => {}
});
@alexmccabe
alexmccabe / markerclusterer.js
Created April 25, 2019 14:17
Fix Google Maps markerclusterer on mobile devices when pinching clusters
// ==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 October 11, 2018 15:20
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.
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') {
const getSiblings = (element) => {
return Array.prototype
.slice
.call(element.parentNode.children)
.filter(item => item !== element);
}
@alexmccabe
alexmccabe / better_get_template_part.php
Last active September 11, 2018 08:51
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 …
<?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
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'
);
}