Skip to content

Instantly share code, notes, and snippets.

View bdunn313's full-sized avatar

Brad Dunn bdunn313

View GitHub Profile
<?php
// Normal php conditional
if (true) {
echo 'This normal one is true!';
} else {
echo 'Its false';
}
// Alternative syntax
if (true):
// Fake network calls again, same as before.
// We don't have to do much besides make it obvious this is async
// async/await enhances Promises, it doesn't replace them!
function fakeNetworkCall(url) {
const promise = new Promise((resolve, reject) => {
setTimeout(() => resolve(url), 1500);
});
return promise;
}
// Fancy new function syntax
fakeNetworkCall('/api/endpoint/1/')
.then(result => fakeNetworkCall('/api/endpoint/2/'))
.then(result => fakeNetworkCall('/api/endpoint/3/'))
// Maybe we finally call a render method on our last request?
.then(result => renderToPage(result))
// Make sure any errors are caught.
.catch(error => handleError(error))
@bdunn313
bdunn313 / promise-example.js
Last active May 30, 2017 03:00
Promise Example
// Simulate a network request by using setTimeout
// This achieves the same thing as our version above.
// This time though, we are going to return a Promise!
function fakeNetworkCall(url) {
const promise = new Promise((resolve, reject) => {
setTimeout(() => resolve(url), 1500);
});
return promise;
}
@bdunn313
bdunn313 / callback-hell.js
Last active May 30, 2017 02:00
modern-javascript-api-consumption
// Simulate a network request by using setTimeout
function fakeNetworkCall(url, callback) {
let returnData = { name: url };
setTimeout(() => callback(returnData), 1500);
};
// Make the first call
fakeNetworkCall('/api/endpoint/1/', (response1) => {
// When the call is done, the callback function
// is called, so we can work with the data here.
@bdunn313
bdunn313 / pg-quick.sh
Last active May 9, 2017 04:01
pg-quick - Quick n Dirty script for standing up a local PostgreSQL DB & User
#!/bin/bash
# Simple script to run the createuser and createdb
# commands after a local/server install of PostgreSQL
# Exit as soon as any line in the bash script fails
# & prints each command executed (prefix with ++)
set -e
# Make sure we have a name parameter
@bdunn313
bdunn313 / can-spam-checklist.md
Created March 25, 2014 01:31
CAN-SPAM Compliance Checklist

CAN-SPAM Compliance Checklist

Reference: BCP Business Center

Do's

  1. Clearly identify message as an Ad.
  2. Give physical location of business.
@bdunn313
bdunn313 / aruba-steps-reference.md
Created December 4, 2012 02:13
Aruba Cucumber Step Definition Reference

Aruba Cucmber Step Definition Reference

This is a short list of all of Aruba's different Cucumber step definitions that are available.

Givens

  1. Given /The default aruba timeout is (\d+) seconds/
  2. Given /^I'm using a clean gemset "([^"]*)"$/
  3. Given /^a directory named "([^"]*)"$/