Skip to content

Instantly share code, notes, and snippets.

View adamcrampton's full-sized avatar
💪
Crushing it

Adam Crampton adamcrampton

💪
Crushing it
  • Sydney, Australia
View GitHub Profile
@adamcrampton
adamcrampton / alexaNodeLambdaBoilerplate.js
Created December 3, 2018 04:30
Simple boilerplate for Lambda function using the Alexa SDK for Node JS
// Alexa Demo
// ==========
'use strict';
// Config Alexa SDK and required libraries.
const Alexa = require('alexa-sdk');
const request = require('request-promise');
// Define handlers.
const handlers = {
@adamcrampton
adamcrampton / lambdaDeploy.sh
Created November 29, 2018 23:25
Shell script for deploying Lambda functions using aws-cli
if [ "$#" -ne 1 ]; then
echo "Usage : ./build.sh lambdaName";
exit 1;
fi
lambda=${1%/}; // # Removes trailing slashes
echo "Deploying $lambda";
cd $lambda;
if [ $? -eq 0 ]; then
echo "...."
@adamcrampton
adamcrampton / eloquentWhereHas.php
Created November 29, 2018 23:01
Laravel Eloquent whereHas query example
class TaxonomyEntity extends Model
{
/**
* Get a list of categories with optional limit and order parameters.
* @param integer $limit
* @param string $order
* @return @return\Illuminate\Database\Eloquent\Collection
*/
public function getCategories($limit = 5, $order = 'DESC')
{
@adamcrampton
adamcrampton / WPCommentQueries.sql
Last active November 21, 2018 23:53
Useful WordPress queries for comments table
-- All live comments
SELECT COUNT(*) FROM wp_comments
WHERE comment_approved = 1
AND comment_date > '2018-08-22'
-- Comment count grouped by author
SELECT COUNT(*) AS comment_count, comment_author, user_id FROM wp_comments
WHERE comment_approved = 1
AND comment_date > '2018-08-22'
GROUP BY user_id
@adamcrampton
adamcrampton / responsiveIframe.html
Created November 19, 2018 23:39
Responsive iframe snippet
<style>
.resp-iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border:0;
}
</style>
@adamcrampton
adamcrampton / differenceBetweenLetAndVar.js
Created November 6, 2018 20:50
Example code describing the difference between let and var in JavaScript
// They are very similar when used like this outside a function block.
let me = 'go'; // globally scoped
var i = 'able'; // globally scoped
// Global variables defined with let will not be added as properties on the global window object like those defined with var
console.log(window.me); // undefined
console.log(window.i); // 'able'
// They are identical when used like this in a function block.
function ingWithinEstablishedParameters() {
@adamcrampton
adamcrampton / getAuthorPostCounts.sql
Created November 6, 2018 05:44
Get WordPress author post counts, within a date range, regardless of current access level
SELECT u.ID, u.display_name, COUNT(*)
FROM wp_posts p
RIGHT JOIN wp_users u ON p.post_author = u.ID
WHERE p.post_type = 'post'
AND p.post_status = 'publish'
AND p.post_date > '2017-11-01 00:00:00'
AND p.post_date < '2018-11-01 00:00:00'
-- Add any exclusions below
-- AND p.post_author NOT IN (8962, 90013, 9256, 52277)
GROUP BY u.display_name
@adamcrampton
adamcrampton / spacetoHyphenRegex.js
Created November 5, 2018 00:34
Replace spaces with hyphens
someString = someString.replace(/\s+/g, '-');
@adamcrampton
adamcrampton / momentTester.js
Created October 30, 2018 01:31
moment.js tester
// Requires moment.js
const moment = require('moment');
// Remove date parameter from moment method to get "now"
var formattedDate = moment('2018-10-29 13:57:37').format('h:mm A');
alert(formattedDate);
@adamcrampton
adamcrampton / stripNonAlphaNumeric.js
Created October 29, 2018 02:13
Strip all non alphanumeric characters from a string
str = str.replace(/[\W_]+/g,'';