Skip to content

Instantly share code, notes, and snippets.

View parkerproject's full-sized avatar

Parker parkerproject

View GitHub Profile
@parkerproject
parkerproject / fileUploadsWithBusboy.js
Created December 24, 2020 20:00 — forked from rhamedy/fileUploadsWithBusboy.js
Upload files with busboy module nodejs and expressjs
//you do not necessary need all of the following, i copy/pasted a piece from
//one of my projects.
var express = require('express');
var fs = require('fs');
var Busboy = require('busboy');
var mime = require('mime');
var https = require('https');
var querystring = require('querystring');
var router = express.Router();
@parkerproject
parkerproject / README.md
Created November 11, 2020 04:40 — forked from atufkas/README.md
rss feed generation from mongojs result using node, express and node-rss

Situation

For my tiny blog (engine) based on node, express/connect and mongojs I needed a simple rss feed solution. I discovered and decided to go with the nice working npm module node-rss instead of writing xml myself.

What this code example does

Basically I create an get event on route /feed/rss, generate a node-rss object initialized with base values and add item elements to it while looping over a mongojs collection result array (holding my post items to be reflected). Finally I send a response with an appropriate content type header. My example is directly bound to an express get event callback for a simple static request path, but you may of course move it to route exports or whatever.

Notes

No big deal, but you might find this portion of code useful as a starting point when seeking for rss solutions.

1/2/2017
moment().format("M/D/YYYY");
01/02/2017
moment().format("MM/DD/YYYY");
14:57:22
moment().format("HH:mm:ss");
02:57 PM
@parkerproject
parkerproject / Page.js
Created September 5, 2020 02:03 — forked from PastorBones/Page.js
NodeJS & Express easy page builder
var Page = function(opt){
var self = this
self.global = {
styles: []
, scripts: []
, keywords: []
}
@parkerproject
parkerproject / downloadString.js
Created June 29, 2020 03:22 — forked from danallison/downloadString.js
download string as text file
function downloadString(text, fileType, fileName) {
var blob = new Blob([text], { type: fileType });
var a = document.createElement('a');
a.download = fileName;
a.href = URL.createObjectURL(blob);
a.dataset.downloadurl = [fileType, a.download, a.href].join(':');
a.style.display = "none";
document.body.appendChild(a);
a.click();
@parkerproject
parkerproject / getTitleNative.js
Created May 4, 2020 13:25 — forked from jbinto/getTitleNative.js
Get title from remote HTML URL - without jQuery
// Only using native browser features (no jQuery).
// Uses `fetch`, `DOMParser` and `querySelectorAll`.
const getTitle = (url) => {
return fetch(`https://crossorigin.me/${url}`)
.then((response) => response.text())
.then((html) => {
const doc = new DOMParser().parseFromString(html, "text/html");
const title = doc.querySelectorAll('title')[0];
return title.innerText;
@parkerproject
parkerproject / start.js
Created March 23, 2020 22:31 — forked from kellyrmilligan/start.js
start.js - adjusted
'use strict';
// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'development';
process.env.NODE_ENV = 'development';
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
@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>