Skip to content

Instantly share code, notes, and snippets.

{
"Title": "TestPage",
"Body": "VGhpcyBpcyBhIHNhbXBsZSBQYWdlLg=="
}
@craigtaub
craigtaub / gist:1574d67e8d41c0a256dc
Last active September 11, 2015 11:07
JS Dev Challenge (context + prototype chain)
function Animal(sound) {
this.makeSound = function () {
return sound;
};
}
function identify() {
return "I am " + this.name;
}
Context:
- object based..ref to object which owns current executing code
- look out for implicit binding
- 'new' operator causes function to be called with 'this' bound to newly created object
Scope:
- function based..can be in function or Global
Prototype chain:
- delegates up prototype chain to function Object.
+someFile.js
let submitButton = require('submitButton');
let markup = submitButton.present(params);
$form.html(markup);
+SubmitButton.js
let template = 'views/partials/submit.mustache'
let mustache = require('mustache');
### What about the other tools?
- PhantomCSS - Image comparison using ResembleJS which did colours well but very little else was caught on testing
- CSS Critic - Does not work on command line
- Wraith - Must run off 2 different domains everytime, is built this way.Takes a while to run (3-5 seconds per image). Built with Ruby so requires the right environment.
### Why not use PhantomJS?
- Did not find any decent image comparison library for it (see PhantomCSS at bottom for more).
- Its not a node module whereas Webshot is a light wrapper around PhantomJS.
-- 1. Parsing hexadecimal values to get the RGB color values.
var hex = 'ffaadd';
var rgb = parseInt(hex, 16); // value is 1675421
var red = (rgb >> 16) & 0xFF; // returns 255
var green = (rgb >> 8) & 0xFF; // 170
var blue = rgb & 0xFF; // 221
----
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: craig-uw-test-project
namespace: default
labels:
app: craig-uw-test-project
public-lb: traefik
spec:
rules:
@craigtaub
craigtaub / gist:bb61f64d311033f2501336ae64260db5
Last active February 26, 2017 22:55
global-leak-finder
var crypto = require('crypto');
function stringifyOnce(obj, replacer, indent = 4) {
var printedObjects = [];
var printedObjectKeys = [];
function printOnceReplacer(key, value) {
// console.log(key);
var printedObjIndex = false;
printedObjects.forEach(function(obj, index) {
@craigtaub
craigtaub / vanilla-redux.js
Last active August 22, 2017 20:01
Vanilla Redux
// -------- declaration of Store, reducers, actions -------- --------
function createStore(reducers) {
let currentSubscribers = [];
const dispatch = (action) => {
const currentState = reducers[action.type](currentState, action);
for (let i = 0; i < currentSubscribers.length; i++) {
currentSubscribers[i](currentState);
}
@craigtaub
craigtaub / vanilla-rexux-sagas.js
Last active August 23, 2017 10:37
WIP - Vanilla Redux Sagas
// -------- declaration of Store -------- --------
const runUntilDone = (iterator) => {
if (!iterator.next().done) {
runUntilDone(iterator);
}
}
function createStore(reducers, sagas) {
let currentSubscribers = [];