Skip to content

Instantly share code, notes, and snippets.

@essamalsaloum
essamalsaloum / 0.md
Created June 15, 2017 11:35 — forked from max-mapper/0.md
JS hoisting by example

JavaScript function hoisting by example

Below are many examples of function hoisting behavior in JavaScript. Ones marked as works successfuly print 'hi!' without errors.

To play around with these examples (recommended) clone them with git and execute them with e.g. node a.js

Notes on hoisting

(I may be using incorrect terms below, please forgive me)

@essamalsaloum
essamalsaloum / index.js
Created July 13, 2017 00:26 — forked from jasongwartz/index.js
HYF Class 8 - Node Homework (Week 1)
// To run this file: node index.js
// Then in your browser: http://localhost:8080
var http = require('http');
var port = 8080;
var server = http.createServer();
// Start the HTTP server, start listening for requests
server.listen(port, function(error) {
@essamalsaloum
essamalsaloum / authentication.js
Created September 15, 2017 15:38 — forked from rts-rob/authentication.js
Basic psuedocode example of a signup/login flow with salt and hash
function signup (email, password) {
const salt = uuid();
const hashedPassword = hash(`${salt}${password}`);
// this stores everything in the DB
createUser(email, salt, hashedPassword);
}
function login (request, response) {
// get the salt - SELECT salt FROM users
// WHERE email = ?, [email]
@essamalsaloum
essamalsaloum / archetype.js
Created September 15, 2017 15:39 — forked from rts-rob/archetype.js
Basic archetype of every express function ever
function archetype (request, response) {
// Get Data out of the request
// Process that data
// Build and send the response
response.setHeaders();
response.write();
response.end();
}
@essamalsaloum
essamalsaloum / user.sql
Created September 15, 2017 15:40 — forked from rts-rob/user.sql
User and Type example showing foreign key constraints and builtin uuid() function for generating id
CREATE TABLE userType (
id int NOT NULL,
description varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE user (
id char(32) NOT NULL, -- use uuid() on INSERT
username varchar(24) NOT NULL, -- rob
passwordHash char(40) NOT NULL, -- c8fed00eb2e87f1cee8e90ebbe870c190ac3848c
@essamalsaloum
essamalsaloum / three-table-join.sql
Created September 15, 2017 15:41 — forked from rts-rob/three-table-join.sql
Example of an INNER JOIN across three tables
CREATE VIEW ClassesAndRunningInformation AS
SELECT
ClassGroup.Name AS ClassGroupName,
Running.StartDate,
Module.Name AS ModuleName,
Module.Length AS ModuleLength
FROM
ClassGroup
INNER JOIN
Running
function Observable(init_value) {
var _value = init_value;
var subscriber = [];
function obs() {
if (arguments.length) {
_value = arguments[0];
obs.trigger();
return this;
} else {
class Observable {
constructor(subscriber) {
this.subscriber = subscriber
}
subscribe(observer) {
if (typeof observer == 'function') observer = {next: observer}
if (!observer.next) observer.next = () => {}
if (!observer.complete) observer.complete = () => {}
@essamalsaloum
essamalsaloum / flightplan-deploy.md
Created November 6, 2017 03:53 — forked from learncodeacademy/flightplan-deploy.md
Deploy Node.js Apps with Flightplan

##Setup your server (this would ideally be done with automated provisioning)

  • add a deploy user with password-less ssh see this gist
  • install forever npm install -g forever

##Install flightplan

  • npm install -g flightplan
  • in your project folder npm install flightplan --save-dev
  • create a flightplan.js file
@essamalsaloum
essamalsaloum / postgres-cheatsheet.md
Created February 2, 2018 23:42 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)