Skip to content

Instantly share code, notes, and snippets.

View johnwargo's full-sized avatar
🏠
Working from home

John M. Wargo johnwargo

🏠
Working from home
View GitHub Profile
@johnwargo
johnwargo / argparse.js
Created November 8, 2016 13:43
Node Command Arguments Parsing
var validArgs = ['some_command', 'another_command'];
//=================================================================
//First lets sort out the command line arguments
//=================================================================
var userArgs;
//Is the first item 'node'? then we're testing
if (process.argv[0].toLowerCase() == 'node') {
//whack the first two items off of the list of arguments
//This removes the node entry as well as the module name entry (the
@johnwargo
johnwargo / onerror.js
Last active November 8, 2016 13:45
JavaScript window.onerror
window.onerror = function (msg, url, line) {
var idx = url.lastIndexOf("/");
if (idx > -1) {
url = url.substring(idx + 1);
}
//Build the message string we'll display to the user
var errStr = "ERROR in " + url + " (line #" + line + "): " + msg;
//Write the error to the console
console.error(errStr);
//Tell the user what happened
@johnwargo
johnwargo / android-post-okhttp
Last active April 16, 2016 22:18
Android HTTP POST Request Using OKHTTP
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.app_menu, menu);
//Only display the menu if the app is in Override mode
if (mIsOverride) {
//First add the click listener for the menu item
MenuItem mItem = menu.findItem(R.id.menu_item_one_time_code);
mItem.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override