Skip to content

Instantly share code, notes, and snippets.

View russellf9's full-sized avatar
🏠
Working from home

Russell Wenban russellf9

🏠
Working from home
  • Factornine Limited
  • London, UK
View GitHub Profile
@russellf9
russellf9 / free-database-hosting.md
Created January 18, 2023 15:10 — forked from bmaupin/free-database-hosting.md
Free database hosting
@russellf9
russellf9 / redux-thunk-examples.js
Created November 18, 2021 11:40 — forked from markerikson/redux-thunk-examples.js
Redux-Thunk examples
// The classic AJAX call - dispatch before the request, and after it comes back
function myThunkActionCreator(someValue) {
return (dispatch, getState) => {
dispatch({type : "REQUEST_STARTED"});
myAjaxLib.post("/someEndpoint", {data : someValue})
.then(
response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}),
error => dispatch({type : "REQUEST_FAILED", error : error})
);
@russellf9
russellf9 / index.js
Last active September 7, 2021 13:16
JS - Utility to format currency (in this case USD)
// format number as currency
export function formatCurrency(amount) {
return new Intl.NumberFormat(`en-US`, {
style: "currency",
currency: "USD",
minimumFractionDigits: 2,
}).format(amount);
}
inOrderDFS(){
// a variable to store the visited nodes
let result = []
// helper function -- accepts a node
function traverse(node){
// if node has left, recursion to find the leftest leaf node
if(node.left) traverse(node.left)
// push the node to the result
result.push(node)
// if node has right, recurstion to find the rightest leaf node
@russellf9
russellf9 / mysql-setup-mac-with-sequel-pro.md
Created July 9, 2021 13:57 — forked from joeyklee/mysql-setup-mac-with-sequel-pro.md
Setting up mysql on mac with sequel pro and homebrew

Setup instructions

Setting up mysql on mac with sequel pro and homebrew

MacOS high sierra 10.13.6
Homebrew version 1.7.6

Assuming you've installed homebrew...

@russellf9
russellf9 / angular-factory-tmpl.xml
Created July 31, 2016 09:53
A IntelliJ Live Template to create an Angular Factory Service
<template name="ngf" value="(function () {&#10;&#10; 'use strict';&#10;&#10;&#10; /**&#10; *&#10; * @author $name$&#10; * @date $date$&#10; *&#10; * @name&#10; * $module$:$factoryName$&#10; *&#10; * @param {obj} $value1$ An accessible member&#10; * @param {function} $function1$ A function the Factory returns&#10; * @param {function} $function2$ A function the Factory returns&#10; *&#10; * // define module requirements&#10; * @requires $dependancy1$&#10; * @requires $dependancy2$&#10; *&#10; * // define `imports`&#10; * @requires $import1$&#10; * @requires $import2$&#10; * &#10; * @description $description$&#10; * Trying to follow the style guidelines from: {https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#angular-docs Angular 1 Style Guide &lt;br&gt;&#10; *&#10; */&#10; &#10; // Ideally each Directive will have a unique package, so this try, catch won`t be required &lt;br&gt;&#10;
@russellf9
russellf9 / angular-directive-tmpl.xml
Last active August 7, 2016 19:51
A Webstorm Live Template, which generates an Angular 1 Directve with a Controller.
<template name="ngsd" value="(function () {&#10;&#10; 'use strict';&#10;&#10;&#10; /**&#10; *&#10; * @author $name$&#10; * @date $date$&#10; *&#10; * @name&#10; * $module$:$directiveName$&#10; *&#10; * @param {data} $input1$ An input two-way binding&#10; * @param {function} $function1$ An output function&#10; * &#10; * @description $description$&#10; * Trying to follow the style guidelines from: {https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#angular-docs Angular 1 Style Guide &lt;br&gt;&#10; * @example&#10; &lt;pre&gt;&#10; &lt;$nameDash$&#10; $inputDash1$='data'&#10; $functionDash1$='update'&gt;&#10; &lt;$nameDash$/&gt;&#10; &lt;pre&gt;&#10; *&#10; */&#10;&#10; try {&#10; module = angular.module('$module$');&#10; } catch (err) {&#10; module = angular.module('$module$', [])&#10; }&#10; &#10; module.directive('$directiveName$', $directiveNa
@russellf9
russellf9 / escapeHtmlEntities.js
Created March 16, 2015 11:35
A function to escape HTML entities
// see: http://stackoverflow.com/questions/1354064/how-to-convert-characters-to-html-entities-using-plain-javascript
// TODO move to $filters
var escapeHtmlEntities = function(text) {
return text.replace(/[\u00A0-\u2666<>\&]/g, function(c) {
return '&' +
(escapeHtmlEntities.entityTable[c.charCodeAt(0)] || '#' + c.charCodeAt(0)) + ';';
});
};
// the wrong kind of entities for our purpose but worth keeping
@russellf9
russellf9 / .jshintrc
Created February 26, 2015 16:08
A default config file for JavaScript Linting jshintrc
{
"globalstrict": true,
"globals": {
"this" : false,
"localStorage": false,
"angular": true,
"Firebase": true,
"Modernizr": true,
"moment" : true,
"tool" : true,
@russellf9
russellf9 / .jscsrc
Created January 18, 2015 18:30
A default config file for JavaScript Code Style - JSCS
{
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch", "case", "default"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"requireParenthesesAroundIIFE": true,
"requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInFunctionExpression": { "beforeOpeningRoundBrace": true },
"requireMultipleVarDecl": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,