Skip to content

Instantly share code, notes, and snippets.

@auchomage
auchomage / gist:026b6380e6621d834c9591b7b1423adc
Created April 15, 2016 02:00
Node.js program, interacts with a user to obtain a person's name & occupation.
console.log('Starting password manager.');
var storage = require('node-persist'); // integrates node-persist module into this application
storage.initSync(); // prepares the computer to write and save variables
var argv = require('yargs')
.command('create', 'Creates a user account', function(yargs){
yargs.options({
name: {
demand: true,
/* This file simulates how to access a native json file*/
var output = document.getElementById('output');
var ajaxhttp = new XMLHttpRequest(); // creates a js object with required functiionality
var url = "json.json"; // the exteranal json file
ajaxhttp.open("GET", url, true); // access the json file
ajaxhttp.setRequestHeader("content-type", "application/json"); // value sent over to the server, indicating
// what type of content the browser expects to receive
/*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example JSON Discoveryvip</title>
<meta name="description" content"Discoveryvip.com>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
/* This file simulates how to access a native json file*/
var output = document.getElementById('output');
var ajaxhttp = new XMLHttpRequest(); // creates a js object with required functiionality
var url = "json.json"; // the exteranal json file
ajaxhttp.open("GET", url, true); // access the json file
ajaxhttp.setRequestHeader("content-type", "application/json"); // value sent over to the server, indicating
// what type of content the browser expects to receive
/*
@auchomage
auchomage / appTest3.js
Created April 24, 2016 01:12
Unable to save using persist my encrypted account, which is in string form
console.log('Starting password manager.');
var storage = require('node-persist'); // integrates node-persist module into this application
storage.initSync(); // prepares the computer to write and save variables
// Encryption/Decryption part
var crypto = require('crypto-js');
var secretKey = "abc";
var masterPassword = "123";
@auchomage
auchomage / app_v2.js
Last active May 1, 2016 21:08
Model answer, not working.
console.log('Starting password manager.');
var crypto = require('crypto-js');
var storage = require('node-persist'); // integrates node-persist module into this application
storage.initSync(); // prepares the computer to write and save variables
/*
var retrievedAccount = storage.getItemSync('account');
console.log("Account is ", retrievedAccount);
*/
@auchomage
auchomage / try-catch-example2.js
Created April 30, 2016 19:30
try-catch example
function doWork(){
// throw an error that says unable to work
console.log("Unable to work!");
}
try {
// call doWork()
throw new Error(doWork());
} catch (e) {
console.log(e.message);
@auchomage
auchomage / try-catch-questions.js
Last active May 1, 2016 21:30
Questions regarding 'try-catch' blocks in node.js
/*
The example provided had a 'throw new Error' statement in the try section
see below
*/
try {
throw new Error('Unable to do the thing you wanted');
} catch(e){
console.log(e.message);
} finally {
@auchomage
auchomage / ex2_accessingJSONdata.html
Created May 2, 2016 16:19
Following a tutorial and am unable to get the code to work
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example JSON Discoveryvip</title>
<meta name="description" content"Discoveryvip.com>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
@auchomage
auchomage / json.json
Last active May 12, 2016 17:18
Problem ajax script: I can get data from an external file (cross site request), but when I try to convert it into javascript I keep getting an error.
{
"firstName": "Henry",
"lastName": "Lawson",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"