Skip to content

Instantly share code, notes, and snippets.

@pdewouters
pdewouters / gist:2598246
Created May 4, 2012 23:05
geocode an address in php
// Geocodes an address and returns an array with long / lat
function do_geocode_address( $address ){
// Send GET request to Google Maps API
$api_url = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=';
$api_response = wp_remote_get( $api_url . urlencode( $address ) );
//Get the JSON object
$json = wp_remote_retrieve_body ( $api_response );
anonymous
anonymous / bonfire-reverse-a-string#.js
Created December 7, 2015 00:15
http://www.freecodecamp.com/jacobarriola 's solution for Bonfire: Reverse a String
// Bonfire: Reverse a String
// Author: @jacobarriola
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function reverseString(str) {
return str.split("").reverse().join("");
}
reverseString("hello");
@mike-north
mike-north / enemy_of_the_state.md
Last active January 11, 2017 04:29
EmberFest 2016 - Enemy of the state
@jacobarriola
jacobarriola / markup.html
Created October 31, 2016 15:49
Blurry to awesome images
<figure class="placeholder" data-large="{path to large image}">
<img src="{path to small image}" class="img-small loaded" alt="{alt}" /> <!-- small image about 50px wide and height to match ratio; keep to less than 3k -->
<div style="padding-bottom: {image ratio}%;"></div> <!-- ratio is height-in-px/width-in-px * 100 -->
</figure>
add_action( 'graphql_register_types', function() {
$post_types = WPGraphQL::$allowed_post_types;
if ( ! empty( $post_types ) && is_array( $post_types ) ) {
foreach ( $post_types as $post_type ) {
$post_type_object = get_post_type_object( $post_type );
/**
* Get the Type name with ucfirst
@kidunot89
kidunot89 / apollo-client.js
Last active July 10, 2020 05:43
useCartMutations - React Hook that use "@apollo-react-hooks", and "uuid" to bundle WooGraphQL cart mutations in a modular tool.
// Node modules
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache, defaultDataIdFromObject } from 'apollo-cache-inmemory';
import { ApolloLink } from 'apollo-link';
import { onError } from 'apollo-link-error';
import { get, isEmpty } from 'lodash';
// Local imports
import { typeDefs, resolvers } from './schema';
@lukecav
lukecav / Command
Last active January 22, 2021 13:07 — forked from BronsonQuick/gist:5185918001f4df5c5d15
Delete ActionScheduler comments and scheduled-action post types in WooCommerce using WP-CLI
wp comment list --field=comment_ID --'comment_author'='ActionScheduler' --number=1000 | xargs wp comment delete --force
wp post list --field=ID --post_type=scheduled-action --posts_per_page=1000 | xargs wp post delete --force
wp post list --field=ID --post_type=scheduled-action --posts_per_page=1000 --post_status=trash | xargs wp post delete --force
wp post list --field=ID --post_type=scheduled-action --posts_per_page=1000 --post_status=cancel | xargs wp post delete --force
@jasonbahl
jasonbahl / order-by-acf-like-count.php
Last active June 13, 2023 16:29
Shows how to add a custom order value to a connection to order by a custom field.
add_filter( 'graphql_PostObjectsConnectionOrderbyEnum_values', function( $values ) {
$values['LIKE_COUNT'] = [
'value' => 'like_count',
'description' => __( 'The number of likes on the post', 'wp-graphql' ),
];
return $values;
} );
sudo curl -o /usr/local/bin/imgcat -O https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat && sudo chmod +x /usr/local/bin/imgcat
# If you have a better way to fix the permissions, comment below!