Skip to content

Instantly share code, notes, and snippets.

View sammoore's full-sized avatar
👩‍🍳
cookin'

Sam Moore sammoore

👩‍🍳
cookin'
View GitHub Profile
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
@sammoore
sammoore / utils1.js
Created February 9, 2017 21:23
Some basic utils. YMMV / not tested.
var utils = {
lists: {
firstOf: function firstOf(collection) {
var keys = Object.keys(collection);
return keys.length > 0 ? collection[keys[0]] : undefined;
},
valueForKey: function valueForKey(collection, key) {
return collection[key];
},
valueForPath: function valueForPath(collection, pathOrKey) {
@sammoore
sammoore / gmaps.TextOverlay.js
Last active February 8, 2017 00:28
An "immutable" OverlayView for Google Maps v3 that simply displays a TextNode in a <div>, anchored at the specified position. Minimal && YMMV.
/* global _, google */
(function amdWeb(root, factory) {
/* eslint-disable */
if (typeof define == 'function' && define.amd) {
define(['lodash', 'googlemaps!'], factory);
/* eslint-enable */
} else {
root.TextOverlay = factory(_, (google || {}).maps);
}
}(this, function factory(_, gmaps) {
var regTrim = = /^\s+|\s+$/g;
@sammoore
sammoore / shallowQueryStringSerializer.js
Created January 24, 2017 19:58
Converts a query string into a key-value array/object. Does not support nested objects (e.g. `?foo[bar]=foobar` becomes `{ 'foo[bar]': 'foobar' }`).
function qsShallowObject(qs) {
var string = qs.indexOf('?') == 0 ? qs.slice(1) : qs.slice();
return (string.split('&')
.map(function (qsEl) {
return qsEl.split('=').map(decodeURIComponent);
})
.reduce(function (query, keyValue) {
query[keyValue[0]] = keyValue[1];
return query;
}, {})
@sammoore
sammoore / websnips.gmail.deleteAll.js
Last active January 21, 2017 20:26
Checks all conversations in the current window and clicks the delete button in Gmail's basic HTML viewer.
// Assumes $ and $$ are aliased to document.querySelector and document.querySelectorAll in the given environment.
$$('[name=t]').reduce(function (d, el) { el.checked = tr; return d; }, $('input[value=Delete]')).click();
@sammoore
sammoore / express-yield.js
Created December 23, 2016 21:51
Middleware for express/similar that adds a primitive 'res.yield' function based on 'res.render' but supports layouts by design. Note: clean-up pending.
// Given 'layout.ejs' in your view folder, use `res.yield` like you would `res.render`.
// Override what layout to use by supplying a second string parameter right after the view.
// Layouts are passed `yield` as a local; in ejs, example usage: `<%- yield %>`.
//
// TODO: clean-up argument coercion
// TODO: better/cleaner documentation for usage of `yield`.
// TODO: extract functionality into a middleware-generating module to supply e.g. a default layout.
// TODO: (possibly) turn the layout's `yield` into a function to support nested yields.
app.use(function (req, res, next) {
// default layout?
@sammoore
sammoore / classicalForEach.js
Last active December 16, 2016 20:28
A forEach function with as little assumptions as possible to iterate over classical collections (array-like objects that must be manually iterated, e.g. integer subscripting or through a `.item(i)` function). Akin to Underscore's _.each/forEach for array-like types only, but with a tidbit more control over iteration. Tested with ES5, but theoret…
/**
* Iterates over `list`, executing `callback` with each element in the collection.
* @requires nothing?
*
* Designed for array-like objects that are not iterable.
* @see https://dom.spec.whatwg.org/#old-style-collections
*
* Due to some versions of Internet Explorer, if `list.item` is defined, it will be treated as a
* function and used rather than integer subscripting. This behavior can be overriden via `useItem`.
* @see http://stackoverflow.com/a/10740835
@sammoore
sammoore / cssInjector.js
Last active December 10, 2016 21:37
Inject CSS properties on the current page based on pre-existing CSS. Tested with jQuery 1.12 for compatibility. Uses browser globals; no support for CommonJS/AMD.
/* Example usage; adds `#menu.hidden { left: -currentValue; }` to <head> in a <script>.
var sel = '#menu';
var source = { selector: sel, prop: 'width' };
var mapWidth = (function (value) { return "-" + value; });
var destination = { selector: sel + '.hidden', prop: 'left', mapping: mapWidth };
var injector = new CSSInjector('menu-css', source, [destination]);
injector.inject('head');
*/
(function ($) {
@sammoore
sammoore / util.inherits.js
Created December 7, 2016 23:36
inherits, as implemented in NodeJS circa ES5, but also defining superClass_ to maintain compatibility with existing in-browser inherits implementations.
'use strict';
function inherits(ctor, superCtor) {
ctor.superClass_ = ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true,