Skip to content

Instantly share code, notes, and snippets.

View parkerproject's full-sized avatar

Parker parkerproject

View GitHub Profile
@parkerproject
parkerproject / app.coffee
Created March 15, 2020 03:43 — forked from AlexNeises/app.coffee
Google Analytics real time dashboard via Node.js
DEVICES = 1000 * 15 # Only call the API once every 15 seconds.
path = require 'path'
google = require 'googleapis'
key = require './config/analytics.json' # This is the key Google Developer has you download upon service account creation.
express = require 'express'
http = require 'http'
https = require 'https'
analytics = google.analytics 'v3'
@parkerproject
parkerproject / advanced-memo.md
Created February 29, 2020 00:22 — forked from slikts/advanced-memo.md
Advanced memoization and effects in React

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory allocation (i.e., value and reference types in C#), but that should just be ignored in JavaScript, because "pass b
@parkerproject
parkerproject / abandoned-cart.js
Created February 19, 2020 12:53 — forked from chexton/abandoned-cart.js
abandoned-cart.js
//1. Grab the first snippet
<script type="text/javascript">
var _veroq = _veroq || [];
_veroq.push(['init', { api_key: 'ce8e305b4c762721725194840ec18fda4f97febd'} ]);
(function() {var ve = document.createElement('script'); ve.type = 'text/javascript'; ve.async = true; ve.src = '//getvero.com/assets/m.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ve, s);})();
</script>
@parkerproject
parkerproject / widget.js
Created November 4, 2019 21:25 — forked from lukencode/widget.js
Starter template for creating jsonp embeddable widgets.
(function () {
var scriptName = "embed.js"; //name of this script, used to get reference to own tag
var jQuery; //noconflict reference to jquery
var jqueryPath = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js";
var jqueryVersion = "1.8.3";
var scriptTag; //reference to the html script tag
/******** Get reference to self (scriptTag) *********/
var allScripts = document.getElementsByTagName('script');
async function doSomething() {
await timeout(2000);
}
function timeout(ms) {
return new Promise((res,rej) => setTimeout(rej,ms));
}
Promise.race([
doSomething(),
timeout(1000)
@parkerproject
parkerproject / removeKeys.js
Created November 5, 2018 20:20 — forked from aurbano/removeKeys.js
Remove a property from a nested object, recursively
/**
* Remove all specified keys from an object, no matter how deep they are.
* The removal is done in place, so run it on a copy if you don't want to modify the original object.
* This function has no limit so circular objects will probably crash the browser
*
* @param obj The object from where you want to remove the keys
* @param keys An array of property names (strings) to remove
*/
function removeKeys(obj, keys){
var index;
@parkerproject
parkerproject / README.md
Created September 19, 2018 23:58 — forked from lukekarrys/ README.md
Node Crawler to find all domain links on a site and run a function on them

Node Crawler to find all domain links on a site and run a function on them

Linked to from http://lukecod.es/2012/11/18/random-problem-of-the-night/

What

This is a node.js crawler that will crawl an entire site (using crawl) to find all internal links in the entire site. It will then test each unique internal link for the presence of an optional string and then the query string into an object. All values with the same key from the query string will be pushed to an array for that key.

Usage

@parkerproject
parkerproject / gulpfile.js
Created August 6, 2018 20:46 — forked from zwacky/gulpfile.js
Example gulpfile.js to get it going with LESS and AngularJS
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var rimraf = require('rimraf');
var paths = {
less: ['./less/*.less'],
js: ['./js/app/*.js', './js/app/**/*.js'],
jsView: ['./js/app/views/*.html'],
dist: {
css: './public/css/',
@parkerproject
parkerproject / ghost.js
Created June 26, 2018 20:32 — forked from aaronmfparr/ghost.js
A node script for making get requests of a Ghost blog's public API. Contains a function and configuration for a single blog.
// -----------------------------------------------------------------------------
// ghost.js
// Usage: node
// Send a get request to a ghost blog and return the response
// Ghost API: https://api.ghost.org/
// -----------------------------------------------------------------------------
//
// 'config' is not strictly necessary, as it is simply used to hold constants
const config = require('./config');
@parkerproject
parkerproject / HOC.js
Created April 5, 2018 05:17 — forked from Restuta/HOC.js
React HOC (Higher Order Component) Example
/* HOC fundamentally is just a function that accepts a Component and returns a Component:
(component) => {return componentOnSteroids; } or just component => componentOnSteroids;
Let's assume we want to wrap our components in another component that is used for debugging purposes,
it just wraps them in a DIV with "debug class on it".
Below ComponentToDebug is a React component.
*/
//HOC using Class
//it's a function that accepts ComponentToDebug and implicitly returns a Class
let DebugComponent = ComponentToDebug => class extends Component {