Skip to content

Instantly share code, notes, and snippets.

View zackproser's full-sized avatar
💭
Studying 📖

Zack Proser zackproser

💭
Studying 📖
View GitHub Profile
@zackproser
zackproser / EmotionalFulcrum.js
Last active August 29, 2015 14:24
An example of how to serve two different endings in your HTML5 Phaser game depending upon player performance.
CanyonRunner.EmotionalFulcrum = function(game) {
this.angelicVoices = null;
};
CanyonRunner.EmotionalFulcrum.prototype = {
create: function() {
this.sound = this.game.add.audioSprite('sound');
this.sound.play('sonar');
@zackproser
zackproser / handle-incoming-twilio-sms.js
Created July 21, 2015 05:16
Demonstrates how to handle an incoming sms POSTed by Twilio.
/**
* Handle incoming sms commands
*
* Verifies that the requestor is authorized - then determines the request type (start / stop attacking)
*
* Finally starts or stops an attack as appropriate
*
* @param {Request} Twilio POST request - generated when a user sends an sms to the associated Twilio number
* @param {Response} Express response
*
@zackproser
zackproser / incoming-call.js
Created July 21, 2015 05:32
A simple route in Express to handle an incoming Twilio call
/**
* Handle a user phoning the Super CatFacts Attack Call Center
*
* @param {Request} - POST request from Twilio - generated when a user calls the associated Twilio phone number
* @param {Response}
* @return {Response} - Response containing valid Twiml as a string - which creates the CatFacts call center experience
*/
app.post('/incoming-call', function(req, res){
res.writeHead(200, { 'Content-Type': 'text/xml' });
res.end(generateCallResponseTwiml().toString());
@zackproser
zackproser / generateTwiml.js
Created July 21, 2015 05:34
An example function for generating Twiml for Twilio to parse during a phone call.
/**
* Generates valid Twiml that creates the Super CatFacts Attack Call Center menu experience
*
* @return {String} response - valid Twiml xml complete with say, play and gather commands
*/
function generateCallResponseTwiml() {
var response = new twilio.TwimlResponse();
response.say("Thank you for calling Cat Facts!", {
voice: 'man',
language: 'en'
@zackproser
zackproser / ivr-call-menu.js
Created July 21, 2015 05:41
An example Twilio-based call menu that accepts and processes user input via touchtone.
/**
* Handle user inputs during the CatFacts Call Center Menu
*
* @param {Request} req Express Request
* @param {Response} res Express Response
*
* @return {[type]} Response containing valid Twiml for Twilio to parse
*/
app.post('/catfacts-call-menu', function(req, res){
//Get the number the user pressed from the Twilio request object
@zackproser
zackproser / process-attack-with-fork.js
Created July 21, 2015 05:53
Demonstrates how to fork a process within an express server in response to a valid command.
/**
* Processes an authorized admin's attack request and launches the attack
*
* Handles tracking the attack child process at the app-level so it can be referenced later / stopped
*
* @param {String} requesting_admin - The phone number of the requesting admin
* @param {String} target - The phone number of the target to be attacked
*
* @return void
*/
@zackproser
zackproser / track-child-processes.js
Created July 21, 2015 06:00
A simple way to keep tabs on child processes in an express app.
/**
* Adds given child_process to the app-level array of running attacks so it can be terminated later
*
* @param {Object} child_process - A node child process representing a currently running attack
*
* @return void
*/
beginTrackingAttack = function(child_process) {
var currentAttacks = app.get('activeAttacks');
currentAttacks.push(child_process);
@zackproser
zackproser / is-target-being-attacked.js
Created July 21, 2015 06:02
Shows how to check for child processes currently running on our express server - looked up by target number.
/**
* Helper method that determines whether or not a supplied number is currently under attack
*
* @param {String} target - the phone number to check for current attacks
* @return {Boolean} targetIsBeingAttacked - Whether or not the given number is under attack
*/
isTargetBeingAttacked = function(target) {
if (target.charAt(0) == '+' && target.charAt(1) == '1'){
target = target.replace('+1', '');
}
@zackproser
zackproser / kill-attack-by-number.js
Created July 21, 2015 06:05
How to look up a child process by a property - and kill it.
/**
* Finds a currently running attack by phone number and terminates it in response to an admin stop attack request
*
* @param {String} requesting_admin - The phone number of the admin requesting a stop
* @param {String} target_number - The phone number that should not be attacked anymore
* @return void
*/
handleAdminStopRequest = function(requesting_admin, target_number) {
var currentAttacks = app.get('activeAttacks');
var foundAttack = false;
@zackproser
zackproser / isPalindrome.js
Created December 18, 2016 01:40
isPalindrome Function in Javascript
/**
* Checks whether a supplied string is a palindrome,
* meaning it is spelled the same forwards and backwards
*
* @param {String} - The string to check
* @return {Boolean} - True, if the string is a palindrome. False, if it is not.
*/
function isPalindrome(stringToCheck) {
/**