Skip to content

Instantly share code, notes, and snippets.

View nateplusplus's full-sized avatar
💭
Groovin'

Nathan Blair nateplusplus

💭
Groovin'
View GitHub Profile
@nateplusplus
nateplusplus / password_protect_posts.php
Last active March 24, 2020 19:41 — forked from pablo-sg-pacheco/functions.php
Wordpress - Password protect a custom post type programmatically
<?php
//Password Protect programmatically
function passwordProtectPosts( $post_object ) {
//Checks if current post is a specific custom post type
if ( $post_object->post_type !== 'tutorial' ) {
return;
}
$post_object->post_password = 'your_password';
@nateplusplus
nateplusplus / Email.js
Last active January 20, 2019 16:35
Using async and await with mysql2 package for node
require('dotenv').config();
const db_creds = {
host : process.env.MYSQL_HOST || '',
user : process.env.MYSQL_USER || '',
password : process.env.MYSQL_PASSWORD || '',
dateStrings : true,
}
const mysql = require('mysql2');
@nateplusplus
nateplusplus / remove_linked_images.php
Last active December 15, 2018 00:51
A migration to remove ALL links from images on all wordpress posts
/**
* A migration to remove ALL links from images on all wordpress posts
* Based on https://gist.github.com/cfxd/219f083465bb5b93fac8#file-remove_wp_selfies-php
**/
function remove_linked_images() {
$all_ids = new WP_Query(array(
'post_type' => array('post'), // feel free to add custom post types here if necessary
'posts_per_page' => -1,
'post_status' => 'publish',
'fields' => 'ids'
@nateplusplus
nateplusplus / Peep.php
Last active July 18, 2018 15:42
Simple php debugging helper function
/**
* Shortcut for print_r or var_dump while debugging
* @param $value (optional) - value, of any type, to print (providing nothing will result in weird face)
* @param bool $vardump (optional) - specify if you prefer var_dump instead of print_r
**/
function peep($value = " ˁ(⦿ᴥ⦿)ˀ ", $vardump = false)
{
echo '<pre>';
if ($vardump || (empty($value) && $value !== 0 && $value !== "0")) {
var_dump($value);
@nateplusplus
nateplusplus / gist:6dcbf630620b07766eb06ab81d7d3d03
Created January 11, 2018 21:06
Accessible jQuery events - it's always more than a simple "click"
$('#elementId').on('click keydown', function(e) {
// Respond to mouse click or enter
if (e.type == 'click' || (e.type == 'keydown' && e.keyCode == 13)) {
e.preventDefault();
e.stopPropagation();
// Do stuff...
}
// Respond to down arrow
@nateplusplus
nateplusplus / mongo_create_database.js
Last active June 11, 2017 17:16
Creating a new database, collection, and document in MongoDB, read more at: http://natehub.blogspot.com/2017/06/learning-mongodb-from-mysql-background.html
// Create and enter new database
use scorecard
// Create new collection named "scorecards" within database "scorecard"
db.createCollection('scorecards');
// Insert data into scorecards collection
db.scorecards.insert({
"title": "Bacon Pancakes",
"players": [
@nateplusplus
nateplusplus / ES2017_do_expression_example.js
Last active June 11, 2017 16:45
ES2017 Do Expression Example - An example of using do expressions to assign a variable in ES2017! Read more at: https://natehub.blogspot.com/2017/05/the-future-of-javascript-and-beyond.html
// Use do expression when assigning variables
var x = do {
function foo() {
return ...
}
var a = 3
foo(a * 7)
};
// Use do expression with try-catch to capture errors when assigning variables
@nateplusplus
nateplusplus / ES2017_async_iteration_example.js
Last active June 11, 2017 16:44
ES2017 Async Iteration Example - An example of using Async Iteration in ES2017, read more on my blog at: https://natehub.blogspot.com/2017/05/the-future-of-javascript-and-beyond.html
async function *getOrders(personId) {
var cursor = db.query( "orders", personId );
do {
let record = await cursor.next();
yield.record;
} while (!cursor.done);
}
async function printOrders(name) {
var person = await lookupPerson( name );
@nateplusplus
nateplusplus / ES2017_spread_properties_example.js
Last active June 11, 2017 16:44
ES2017 Spread Properties Example - An example of using spread properties in ES2017 for my blog at https://natehub.blogspot.com/2017/05/the-future-of-javascript-and-beyond.html
function lookupRecord(id, ...otherParams) {
return db.lookup(
"people-records", id, ...otherParams
);
}
function getSomeData() {
var someVals = [2,3];
return [1,...someVals,4];
@nateplusplus
nateplusplus / to-top.css
Created December 8, 2015 16:00
A little script I wrote for a pop-up button that scrolls users to top of page.
#to-top {
text-decoration: none;
color: white;
transition: color 0.15s ease, transform 0.5s ease;
position: fixed;
bottom: 2em;
right: 2em;
text-align: center;
padding: 0 0.5em;
}