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 / html5_boilerplate.html
Last active January 23, 2019 19:11
Basic Responsive HTML5 Boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Website</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
</body>
</html>
@nateplusplus
nateplusplus / Page.js
Last active December 8, 2015 15:36
A little project I was trying out, which uses object oriented javascript to get the url hash, and find the appropriate template to render... or you could just use angular.
function Page(urlhash) {
'use strict';
this.hash = {
"value": urlhash,
"name": ""
}
}
Page.prototype.getHashName = function () {
@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;
}
@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 / 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_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 / 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 / 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 / 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 / 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'