Skip to content

Instantly share code, notes, and snippets.

@pentaphobe
pentaphobe / composeControllers.js
Created December 9, 2016 01:05
Compose controller functions
/**
*
* Late night framework experiment with @pmarabeas
*
*/
'use strict';
var angular = require('angular');
@pentaphobe
pentaphobe / objToCsv.js
Last active March 9, 2017 00:43
CSV generator example
'use strict';
let objToCsv = (function() {
let defaultOptions = {
showLabel: true,
lineBreak: '\r\n',
separator: ','
};
// escape quotes
@pentaphobe
pentaphobe / updateIn.js
Created April 21, 2017 04:32
Alternate updateIn() for ImmutableJS
/**
* Convenience function for deep updates including searches in the path
*/
export default function updateIn(immutableType, pathArray, updater) {
// pathArray can contain matcher functions
let failed = false;
let parsedPath = [];
pathArray.every( (pathEl, idx) => {
if (typeof pathEl !== 'function' && typeof pathEl !== 'object') {
@pentaphobe
pentaphobe / scanning_demo.js
Last active July 1, 2017 09:05
Demonstration of scanning xor-encrypted data
/**
* This is an insultingly simple demo due to nerd rage
*
* There are claims of people using static XOR keys to hide shell code in malware
*
* The only thing more embarrassing than this is that it supposedly prevent detection.
*
*/
@pentaphobe
pentaphobe / wrapTest.js
Created August 1, 2017 06:38
Auto wrapping of functions
let basis = {
hello: (name) => console.log(`hello ${name}!`)
};
function wrap(fn, name, ctx) {
return function() {
let args = Array.prototype.slice.call(arguments);
console.log(`wrapped function ${name}`, args);
return fn.apply(ctx, args);
@pentaphobe
pentaphobe / matchAll.js
Created August 1, 2017 10:27
JS regex matchAll
'use strict';
function matchAll(re, str) {
let result = [], tmp;
while ( (tmp = re.exec(str)) !== null ) {
tmp.shift();
result = result.concat(tmp);
}
return result;
}
@pentaphobe
pentaphobe / zipInterleaved.js
Last active August 1, 2017 10:37
ZIP interleaved array into object
function zipInterleaved(arr) {
return arr.reduce( (prev, cur, idx) => {
if (idx % 2 == 0) {
return {obj:prev, key:cur};
} else {
let obj = prev.obj;
obj[prev.key] = cur;
return prev.obj;
}
}, {});
'use strict';
var _templateObject = _taggedTemplateLiteral(['\n @media screen and (min-width: 980px){\n ', '\n }\n '], ['\n @media screen and (min-width: 980px){\n ', '\n }\n ']),
_templateObject2 = _taggedTemplateLiteral(['\n @media screen and (min-width: 768px) {\n ', '\n }\n '], ['\n @media screen and (min-width: 768px) {\n ', '\n }\n ']),
_templateObject3 = _taggedTemplateLiteral(['\n @media screen and (min-width:480px) {\n ', '\n }\n '], ['\n @media screen and (min-width:480px) {\n ', '\n }\n ']),
_templateObject4 = _taggedTemplateLiteral(['\n *, ::after, ::before {\n box-sizing: border-box;\n }\n\n body {\n margin: 0;\n font-family: \'myriad-pro\', sans-serif;\n color: ', ';\n -webkit-font-smoothing: antialiased;\n min-width: 320px;\n }\n\n a {\n color: ', ';\n text-decoration: none;\n\n &:hover,\n &:focus {\n text-decoration: underl
@pentaphobe
pentaphobe / ads-declarative.js
Created September 27, 2017 03:58
Integration test files
'use strict';
// here is where we'd bring in our glue library
//
// (this is just a placeholder for same)
let ADS_COMPONENT = `data-ads-component`;
let E_DEPENDENCY = 'Either include as an external script, or as a bundled dependency';
let E_NO_REACT = 'No React found.';
import {flowRight, set} from 'lodash-fp'
const foo = (obj) => flowRight(
set('noodles', 'yes please'),
({a, b, c}) => {
console.log(a,b,c);
return obj
}
)