Skip to content

Instantly share code, notes, and snippets.

@garrettmac
garrettmac / app.js
Last active July 21, 2017 18:31
simple gulp recipe to sever any projects dist folder with express & node. Just add these to a project then move any project you'd like to server at the root and rename the folder 'frontend' and you're done
'use strict';
// simple express server
var express = require('express');
var app = express();
var router = express.Router();
app.use(express.static('public'));
app.get('/', function(req, res) {
// res.sendfile('./public/index.html');
@garrettmac
garrettmac / paginatiion-math.js
Last active July 29, 2017 15:21
paginatiion-math.js
page = Math.abs(parseInt(page) || 1)
console.log(" page: ",page);
//results to return
pageSize = parseInt(pageSize) || 10
//cannot go above 50
if(pageSize > maxsize)pageSize=maxsize
// limits payload size
let total= (µœ.data.length)
@garrettmac
garrettmac / React-Native-Swift-Module-Starter.md
Last active August 7, 2017 00:22
React-Native-Swift-Module-Starter.md
// RNSocialKitBridge.m
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(RNSocialKit, NSObject)

RCT_EXTERN_METHOD(addEvent:(NSString *)name location:(NSString *)location date:(nonnull NSNumber *)date)

@end
@garrettmac
garrettmac / animation-panresponder.md
Last active August 16, 2017 17:35
Blog Posts for React Native - Post 1:Native ModulesPost 2: Pan Responder (Animation)

Lets start with boiler template

/* @flow */

import React, { Component } from 'react';
import {
  View,
  TouchableOpacity,
  Text,

There are four types of legislation that move through Congress:

Bills and three types of resolutions.

Generally, bills are legislative proposals that, if enacted, carry the force of law, whereas resolutions do not. Though, this is not always true.

Bills Vs Resolutions.

Bills

Bills, are legislative proposals that, if enacted, carry the force of law.

Lifecycle (in order) Triggered When Use When
getDefaultProps Triggered when Useful when
The result of getDefaultProps() will be cached and used to ensure that this.props.value will have a value if it was not specified by the parent component.
componentWillMount() Triggered before render(). Useful when
componentDidMount() Triggered Called after render. Can access refs. The componentDidMount() method of child components is invoked before that of parent components. This is the place to call external libraries, use setTimeout, make ajax requests Useful when
shouldComponentUpdate(nextProps, nextState) Triggered when updates Useful when called when there are new props or state changes. return false to prevent a render. good for performance.
componentWillReceiveProps(nextProps) Triggered when view is updated Useful when Called before render when props change. Access to old
@garrettmac
garrettmac / 1-Inheritance-Example-es5.js
Last active September 15, 2017 02:52
MEDIUM BLOG POST
/* in ES5 */
//create Person
function Person () {}
// Person Inheritance a name through the prototype keyword
Person.prototype.name = “Garrett Mac”;
//Person is a constructor function because we will use new keyword to invoke it.
@garrettmac
garrettmac / 2-functionsal-composition-how.js
Created September 15, 2017 04:12
MEDIUM BLOG POST - Javascript’s 3 Major Paradigms: The Five tenets of Functional Programming [part 3 of 4]
const vehicles = [
 { make: ‘Honda’, model: ‘CR-V’, type: ‘suv’, price: 24045 },
 { make: ‘Honda’, model: ‘Accord’, type: ‘sedan’, price: 22455 },
 { make: ‘Mazda’, model: ‘Mazda 6’, type: ‘sedan’, price: 24195 },
 { make: ‘Mazda’, model: ‘CX-9’, type: ‘suv’, price: 31520 },
 { make: ‘Toyota’, model: ‘4Runner’, type: ‘suv’, price: 34210 },
 { make: ‘Toyota’, model: ‘Sequoia’, type: ‘suv’, price: 45560 },
 { make: ‘Toyota’, model: ‘Tacoma’, type: ‘truck’, price: 24320 },
 { make: ‘Ford’, model: ‘F-150’, type: ‘truck’, price: 27110 },
@garrettmac
garrettmac / 1-Higher-order-functions-how.js
Last active September 15, 2017 04:12
MEDIUM BLOG POST - Javascript’s 3 Major Paradigms: The Five tenets of Functional Programming [part 3 of 4]
const vehicles = [
 { make: ‘Honda’, model: ‘CR-V’, type: ‘suv’, price: 24045 },
 { make: ‘Honda’, model: ‘Accord’, type: ‘sedan’, price: 22455 },
 { make: ‘Mazda’, model: ‘Mazda 6’, type: ‘sedan’, price: 24195 },
 { make: ‘Mazda’, model: ‘CX-9’, type: ‘suv’, price: 31520 },
 { make: ‘Toyota’, model: ‘4Runner’, type: ‘suv’, price: 34210 },
 { make: ‘Toyota’, model: ‘Sequoia’, type: ‘suv’, price: 45560 },
 { make: ‘Toyota’, model: ‘Tacoma’, type: ‘truck’, price: 24320 },
 { make: ‘Ford’, model: ‘F-150’, type: ‘truck’, price: 27110 },
@garrettmac
garrettmac / 3-recursion-how.js
Created September 15, 2017 04:14
MEDIUM BLOG POST - Javascript’s 3 Major Paradigms: The Five tenets of Functional Programming [part 3 of 4] Copy Raw
function iterativeFactorial(n) {
 let product = 1;
 for (let i = 1; i <= n; i++) {
 product *= i;
 }
 return product;
}