Skip to content

Instantly share code, notes, and snippets.

@csknk
csknk / Cors.php
Last active December 6, 2019 08:30
Set up CORS on a Laravel API to respond to an Axios request with an 'OPTIONS' preflight.
<?php
// app/Http/Middleware/Cors.php
// It's possible to generate the file with artisan (see comment)
namespace App\Http\Middleware;
use Closure;
class Cors
{
@brenna
brenna / wp-autopopulate-taxonomy
Last active December 26, 2022 23:29
WordPress function to auto-populate a taxonomy with a custom post type's entries.
function custom_tax_init(){
//set some options for our new custom taxonomy
$args = array(
'label' => __( 'My Custom Taxonomy' ),
'hierarchical' => true,
'capabilities' => array(
// allow anyone editing posts to assign terms
'assign_terms' => 'edit_posts',
/* but you probably don't want anyone
@bpmore
bpmore / kill-fusion.php
Created April 6, 2017 03:11
remove fusion builder shortcodes
<?php
add_filter('the_content', 'remove_fusion_shortcodes', 20, 1);
function remove_fusion_shortcodes( $content ) {
$content = preg_replace('/\[\/?fusion.*?\]/', '', $content);
return $content;
}
?>
**Tested with WP All Import and Export**
@JamieMason
JamieMason / group-objects-by-property.md
Created September 14, 2018 07:38
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@benwells
benwells / reduce-example.js
Created May 12, 2016 13:40
Using Array.reduce to sum a property in an array of objects
var accounts = [
{ name: 'James Brown', msgCount: 123 },
{ name: 'Stevie Wonder', msgCount: 22 },
{ name: 'Sly Stone', msgCount: 16 },
{ name: 'Otis Redding', msgCount: 300 } // Otis has the most messages
];
// get sum of msgCount prop across all objects in array
var msgTotal = accounts.reduce(function(prev, cur) {
return prev + cur.msgCount;
@jonathantneal
jonathantneal / README.md
Last active March 19, 2024 23:31
Local SSL websites on macOS Sierra

Local SSL websites on macOS Sierra

These instructions will guide you through the process of setting up local, trusted websites on your own computer.

These instructions are intended to be used on macOS Sierra, but they have been known to work in El Capitan, Yosemite, Mavericks, and Mountain Lion.

NOTE: You may substitute the edit command for nano, vim, or whatever the editor of your choice is. Personally, I forward the edit command to Sublime Text:

alias edit="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
@Chandler
Chandler / slack_history.py
Last active March 26, 2024 14:35
Download Slack Channel/PrivateChannel/DirectMessage History
print("UPDATE AUG 2023: this script is beyond old and broken")
print("You may find interesting and more up to date resources in the comments of the gist")
exit()
from slacker import Slacker
import json
import argparse
import os
# This script finds all channels, private channels and direct messages
@chrismccoy
chrismccoy / restapi.txt
Last active March 30, 2024 08:17
WordPress REST API Resources
Disable REST Api without Plugins
https://rudrastyh.com/wordpress/disable-rest-api.html
Add featured image & alt text to WP REST API
https://allisontarr.com/2021/10/13/add-featured-image-alt-text-to-wp-rest-api/
Allow ALL cross origin requests to WordPress REST API
https://github.com/Shelob9/rest-all-cors
WordPress theme using Rest API and Vue.js
@jjmu15
jjmu15 / in_viewport.js
Created January 27, 2014 10:19
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);