Skip to content

Instantly share code, notes, and snippets.

@stephentuso
stephentuso / functional-logic.js
Last active March 2, 2018 05:25
Concisely perform multiple checks on the same value
export const and = (func, ...funcs) => (...args) => (
funcs.length
? func(...args) && and(...funcs)(...args)
: func(...args)
);
export const or = (func, ...funcs) => (...args) => (
funcs.length
? func(...args) || or(...funcs)(...args)
: func(...args)
@stephentuso
stephentuso / jsdoc-plugin-undocumented.js
Last active November 28, 2017 15:49
This includes undocumented functions in the docs - ideally everything would be properly documented, but this is a quick fix if you have a huge number of undocumented functions
'use strict'
exports.handlers = {
symbolFound: function (e) {
let params = e.code.paramnames
let filename = e.filename.split('doc-stage/')[1].split('.js')[0]
if (filename === 'module.exports' || filename === 'exports') {
return
}
let type = e.astnode.type
if (type === 'Property') {
#!/bin/bash
# OS X Android icon resizer
# Resizes icon and puts in corresponding folders
# Usage: android-resizer [image path] [mdpi size] [out dir]
# If no out directory supplied, uses directory from image path
if [[ $# -lt 2 ]]
then
echo "Error: Please supply image file path and mdpi size"
@stephentuso
stephentuso / jQuery-create-elements-v2.js
Last active June 19, 2017 15:48
Function to make creating DOM elements with jQuery easier and more readable
// v2: more similar to render functions used by React, Vue, etc
// Example usage:
create('div', [
['h1', { 'class': 'foo' }, 'Bar'],
['p', 'Lorem ipsum dolor']
])
// OR
create('div', [
create('h1', { 'class': 'foo' }, 'Bar'),
function injectPage(url) {
var CONTAINER_SELECTOR = '.content';
//Show loading indicator
document.querySelector(CONTAINER_SELECTOR).innerHTML = '<center>Loading...</center>';
url = decodeURI(url);
var xhr = new XMLHttpRequest();
@stephentuso
stephentuso / gulpfile.js
Last active December 7, 2016 21:45
gulpfile I use for polymer
/**
Structure used:
Source files are in /app
There are php files in /app/private_php and /app/public_php
Static files (elements, bower_components) are in /app/static
Builds into /dist-dev and /dist-prod
*/
var gulp = require('gulp');
#!/bin/bash
# OS X Android icon resizer
# Resizes icon and puts in corresponding folders
# Usage: android-icon-resizer [image path] [mdpi size] [out dir]
# If no out directory supplied, uses directory from image path
if [[ $# -lt 2 ]]
then
echo "Usage: android-icon-resizer [image path] [mdpi size] [out dir]"