Skip to content

Instantly share code, notes, and snippets.

View johnfkneafsey's full-sized avatar

John F Kneafsey johnfkneafsey

View GitHub Profile
1) What is a hash function?
A hash function is a function that takes a password string and "hashes" it, or encodes it, using an algorithm meant to hide the original password.
2) What is a one-way hash?
One way hashes are hashed strings that are almost impossible to reverse.
3) What is the problem with storing passwords as plain text?
Plain text passwords can be comprised by hackers. Typically if a hacker can get their hands on one user's password they will be able to access multiple accounts because users tend to reuse passwords.
4) How does HTTP Basic Authorization work?
1) What is Knex used for?
Knex is used to make SQL queries using JS.
2) How do you connect to a Postgres Database using Knex?
const knex = require('knex')({
client: 'pg',
connection: {
user: 'username',
password: 'password',
database: 'database'
1)
create table if not exists TABLENAME (
id serial primary key,
//add additional columns
2)
insert into TABLENAME (COLUMN1NAME, COLUMN2NAME)
values ('VALUEFORCOLUMN1', 'VALUEFORCOLUMN2);
3)
@johnfkneafsey
johnfkneafsey / get.js
Last active December 19, 2016 02:29
GET endpoint
app.get('/test', function (req, res) {
res.send('Now viewing the test page')
})
function getDataFromApi(callback) {
var settings = {
url: "https://api.github.com/gists/public",
dataType: 'json',
type: 'GET',
success: callback
};
$.ajax(settings);
}
function mergeDataStreams(stream1, stream2) {
var results = {};
for (var i=0; i < stream1.length; i++) {
results[stream1[i].id] = stream1[i];
}
for (var key in results) {
var otherData = stream2.find(
function(item) { return item.id === key; });
for (var _key in otherData) {
@johnfkneafsey
johnfkneafsey / Object Drills
Created November 22, 2016 16:01
Object Drills
function createMyObject() {
return {
foo: 'bar',
answerToUniverse: 42,
'olly olly': 'oxen free',
sayHello: function() {
return 'hello';
}
};
}
@johnfkneafsey
johnfkneafsey / In my own words
Created November 22, 2016 15:47
In my own words
What is scope? Your explanation should include the idea of global vs. local scope.
Scope is a term used to classify parts of your code that have access to a variable. If the scope of the variable is local, any code inside the function can access the variable. Any code outside the function cannot. If the scope of a variabel is global, it means that the variable can be accessed from anywhere.
Why are global variables avoided?
Global variables can be bad for a variety of reasons- they make it difficult to work collaboratively, they can lead to bugs in your code that are difficult to untangle, you can run into concurrency issues, you may confuse global and local variable names, and so on.
Explain JavaScript's strict mode
JS's strict mode disables the use of global variables, forcing the user to define all variables locally.
What are side effects, and what is a pure function?
@johnfkneafsey
johnfkneafsey / Array Drills
Created November 22, 2016 15:24
Array Drills
function max(numbers) {
var currentMax = numbers[0];
for (var i=0; i <= numbers.length; i++) {
if (numbers[i] > currentMax) {
currentMax = numbers[i];
}
}
return currentMax;
}
@johnfkneafsey
johnfkneafsey / Logic Drills
Created November 22, 2016 00:54
Logic Drills
function main() {
try {
doAllTheThings();
}
catch(e) {
console.error(e);
reportError(e);
}
}