Skip to content

Instantly share code, notes, and snippets.

View jonathan-fulton's full-sized avatar

Jonathan Fulton jonathan-fulton

View GitHub Profile
@jonathan-fulton
jonathan-fulton / example.js
Last active June 15, 2017 23:40
Simple SFV example
class Router {\
registerRoutes() {
this.post('/user', UserController.create);
}
}
class UserController {
create(req, res) {
this._userService.createFromRequest(req)
.then(user => res.send(user.toJSON()));
@jonathan-fulton
jonathan-fulton / badsignupform.php
Created June 15, 2017 19:00
Bad PHP Code from A Long Time Ago
<?php
if($_SERVER['SERVER_PORT'] != '443') { header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit(); }
require $_SERVER["DOCUMENT_ROOT"] . "/common.php";
require $_SERVER["DOCUMENT_ROOT"] . "/classes/libs/google/gcookie.class.php";
if ($language == 'en') header ("location: $sitesecureurl/freeclips/");
$ga = new GA_Parse($_COOKIE);
@jonathan-fulton
jonathan-fulton / UserService.js
Created June 15, 2017 17:14
Example of a side effect
function getUserByEmailAndPassword(email, password) {
let user = UserService.getByEmailAndPassword(email, password);
if (user) {
LoginService.loginUser(user); // Log user in, add cookie (Side effect!!!!)
}
return user;
}
@jonathan-fulton
jonathan-fulton / build-url.js
Created June 15, 2017 16:48
build-url: the good way
function buildUrl(url, options) {
const baseUrl = _getBaseUrl(url);
const opts = _getOptions(url, options);
if (!opts) {
return baseUrl;
}
urlWithPath = _appendPath(baseUrl, opts.path);
urlWithPathAndQueryParams = _appendQueryParams(urlWithPath, opts.queryParams)
@jonathan-fulton
jonathan-fulton / build-url.js
Last active May 14, 2018 00:59
build-url: the bad way
function buildUrl(url, options) {
var queryString = [];
var key;
var builtUrl;
if (url === null) {
builtUrl = '';
} else if (typeof(url) === 'object') {
builtUrl = '';
options = url;