Skip to content

Instantly share code, notes, and snippets.

View cerebrl's full-sized avatar

Justin Lowery cerebrl

View GitHub Profile
@cerebrl
cerebrl / mixinFactory.js
Created August 26, 2015 03:22
A mixin factory for building horizontal inheritance.
/** ****************************************
* Utility file
* mixin.js
* @returns [object]
*/
function mixinFactory() {
var len = arguments.length,
i = 0,
finalObj = {};
@cerebrl
cerebrl / constructor-prototype.js
Last active August 26, 2015 04:38
Making a "class" in JavaScript. What we typically see when we code up the M in MVC.
/** ****************************************
* Constructor for say hi feature.
* @constructor SayHiConstructor
* @returns {object}
*/
function SayHiConstructor() {
this.greeting = "Basic module says, 'hallo'!"
}
SayHi.prototype.sayHi = function sayHi() {
this.writeToConsole());
@cerebrl
cerebrl / module-api.js
Last active August 26, 2015 04:56
An alternative to the Constructor/Prototype pattern typically seen in web applications: a basic module pattern returning an API. JSBin here: http://jsbin.com/nuqizaziko/edit?js,console
/** ****************************************
* Module for say hi feature
* @module sayHiFactory
* @returns {object}
*/
function sayHiFactory() {
var greeting = "Basic module says, 'hallo'!"
function prvtWriteToConsole() {
console.log(greeting);
@cerebrl
cerebrl / safeGet.js
Created February 12, 2015 21:41
Be able to safely access props on deep objects. Demo: http://jsbin.com/beferuviqo/1/edit
// Sample object
var mySampleData = {
foo: {
bar: [
1,
2,
{
baz: "hello",
wut: 2,
hi: [7, 8, 9]
@cerebrl
cerebrl / factories-mixins-inheritence.js
Created August 2, 2015 03:17
Playing with factories, prototypes, behavior delegation, mixins and more: http://cerebrl.jsbin.com/zaxaqo/edit?js,console …. I love JavaScript!
/** ****************************************
* Utility file
* mixin.js
* @returns [object]
*/
function mixinFactory() {
var len = arguments.length,
i = 0,
finalObj = {};
@cerebrl
cerebrl / front-end_standards-of-practice.md
Last active December 16, 2015 07:28
Front-End Standards of Practice

Front-End Processes, Workflows and Standards

  1. Definition: The front-end consists of any code that is run on the client (browser): HTML, CSS and JavaScript.
  2. Agnostic and independent front-end code is priority. Front-end code should not represent server/back-end architecture.
  3. Modularity and encapsulation is vital to increase reusability and following the DRY philosophy.
  4. The MVC philosophy (when developing web-applications) should be closely followed, but exact replication may be unnecessary. The structure goes as follows:
    • Model: Models do not technically exist in the client (unless using client-sided storage (localStorage, et cetera), but act more as temporary data stores between getting and setting data with the server. So, this temporary data store will be considered and called a Service. Data should always exist as native JSON either as objects or arrays.
    • View: Views should be pure HTML containing virtually no logic. Element attributes (data-, classes, ids, ng-model,
@cerebrl
cerebrl / angular-localStorage.md
Created June 28, 2013 17:39
localStorage with AngularJS

AngularJS localStorage

This was nabbed from DailyJS

There are examples of apps that use localStorage on the AngularJS blog. One that I downloaded and picked apart was FoodMe by Igor Minar. In FoodMe, Igor creates a localStorage service which basically just wraps window.localStorage so it can be loaded with dependency injection. The $scope is then watched, and a string version of a given record is dumped into localStorage using JSON.stringify:

foodMeApp.factory('customer', function($rootScope, localStorage) {
	var LOCAL_STORAGE_ID = 'fmCustomer';
	var customerString = localStorage[LOCAL_STORAGE_ID];
@cerebrl
cerebrl / .bash_profile
Last active December 19, 2015 03:28
Bash Aliases
alias gitA="git add -A && git status "
alias gitS="git status "
alias gitPl="git pull "
alias gitCm="git commit -m "
alias gitACm="gitA && gitCm "
alias gitPPM="git pull && git push origin master "
alias gitPB="git push origin "
alias gitPg="git checkout gh-pages && git push origin gh-pages && git checkout master && git branch -d gh-pages"
alias gitCkM="git checkout master "
alias gitStPlPhi="git subtree pull --prefix=phi git@github.com:cerebralideas/phi.git "
@cerebrl
cerebrl / .jshintrc
Created July 4, 2013 01:38 — forked from haschek/.jshintrc
JSHint Options File
{
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true