Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
cmawhorter / doc-update-partial.js
Last active September 8, 2017 22:51
Automate DynamoDB doc.update call by generating the required attributes from an object literal.
// Note: This takes your data keys and drops them directly into the
// UpdateExpression. If you have more exotic key names, this will likely
// fail because 'this is a valid key name' works in javascript but not the
// dynamodb client.
var keyName = 'thePartitionKey';
var data = {
thePartitionKey: '1231342142321321',
message: 'your partial data i.e. the fields you want updated in the target document'
};
@cmawhorter
cmawhorter / mithril-table-example.html
Created March 3, 2017 19:19
concept of loading mithril components and passing around data structures
<body>
<script>
// our data returned from server
var myMockEventObject = {
id: 'trkevt_1',
created: '',
updataed: '',
};
// pretend data returned from server
@cmawhorter
cmawhorter / index.js
Created February 13, 2017 19:36
lambda hello world
module.exports.handle = function(event, context, callback) {
callback(null, 'hello world!');
};
@cmawhorter
cmawhorter / blah.js
Created January 24, 2017 19:52
rollup lazy top scope for node deps thoughts
let nodeDeps = {};
let nodeCache = {};
// some dependency
Object.defineProperty(nodeDeps, 'some_module', {
get: () => {
if (process.argv[2] !== 'hello') throw new Error('hello must be first argument');
const nodeModule = nodeCache.some_module || { world: () => console.log('world') };
return nodeModule;
}
@cmawhorter
cmawhorter / build.js
Created January 20, 2017 02:19
rollup and babel cwd
'use strict';
const path = require('path');
const rollup = require('rollup');
const babel = require('rollup-plugin-babel');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const builtins = require('rollup-plugin-node-builtins');
const globals = require('rollup-plugin-node-globals');
'use strict';
var assert = require('assert');
var AWS = require('aws-sdk');
var dynogels = require('dynogels');
var Enjoi = require('enjoi');
var config = {
endpoint: 'http://localhost:8000',
};
@cmawhorter
cmawhorter / mithril-delayed-route-set.js
Created November 28, 2016 00:21
delayed m.route.set for mithril v1 to avoid redirect loops freezing or crashing the browser
if (ENV === 'development') {
var m_route_set = m.route.set;
var lastCall = new Date().getTime();
var minDelayBetweenCalls = 100;
m.route.set = function() {
var args = arguments;
var now = new Date().getTime();
var elapsed = now - lastCall;
lastCall = now;
setTimeout(function() {
@cmawhorter
cmawhorter / mithril-v1-server-render.js
Created November 26, 2016 23:32
mithril v1 on the server. created for dev/testing and prod.
'use strict';
var MockBrowser = require('mock-browser').mocks.MockBrowser;
var jsdom = require('jsdom');
function propagateToGlobal (window) {
for (var key in window) {
if (!window.hasOwnProperty(key)) continue
if (global[key]) {
@cmawhorter
cmawhorter / find-elements-that-are-too-wide.js
Last active September 2, 2016 07:38
Checks every element in a page to see if it's total width is wider than the container (viewport by default). Might be useful to track down unwanted horizontal scroll bars.
// Deps on jquery
(function(container) {
var viewportWidth = $(container).width();
console.group('Overflow Check');
console.info('Container Width: %s', viewportWidth);
$('*').each(function() {
var $this = $(this);
var elWidth = $this.outerWidth(true);
if (elWidth > viewportWidth) {
console.warn('Overflow by %spx!', elWidth - viewportWidth, loggingVars, this);
@cmawhorter
cmawhorter / grunt-build.bat
Last active April 19, 2016 13:30
Script to build grunt/yeoman project from jenkins on windows 7
@echo off
REM You may need to add `cd %WORKSPACE%` in the jenkins project prior to
REM calling this script. I have it in mine and didn't test without.
REM Correct paths to respective applications as-needed
SET PATH=%PATH%;C:\Program Files (x86)\nodejs;C:\Program Files (x86)\Git\bin;%AppData%\npm;C:\Ruby200-x64\bin
echo Installing or updating bower...