This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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": [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lookupRecord(id, ...otherParams) { | |
return db.lookup( | |
"people-records", id, ...otherParams | |
); | |
} | |
function getSomeData() { | |
var someVals = [2,3]; | |
return [1,...someVals,4]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
NewerOlder