Skip to content

Instantly share code, notes, and snippets.

@emilhein
emilhein / Array manipulation
Last active March 5, 2018 11:32
Functional ramda
const R = require('ramda')
let object = [{
Name: 'a',
Records: [{
Value: '1.2.3.4.5'
}],
Type: 'winner'
},
{
@emilhein
emilhein / wait promise aync
Last active July 8, 2018 14:47
es6 wait with asyn to "throotle" promises
const timeout = ms => new Promise(res => setTimeout(res, ms))
async function delayFunc(delay, func, input) {
await timeout(delay)
return func(input)
}
let myPromise = input => {
return new Promise((resolve, reject) => {
console.log('HI ', input)
const fetch = require('node-fetch');
const getPostObj = ({ branch = 'main', msg = 'auto commit', content = '', file_path = null, action = 'update' }) => ({
branch,
commit_message: msg,
"actions": [
{
action,
file_path,
content
let obj = [...Array(11).keys()].reduce((prev, current) => {
prev[current] = true
return prev
}, {})
console.log(obj);
/*
{ 0: true,
1: true,
function executeSequentially(promiseFactories) {
var result = Promise.resolve();
promiseFactories.forEach(function (promiseFactory) {
result = result.then(promiseFactory);
});
return result;
}
const logger = async (input) => {
console.log('Heelloo', input)
}
//CLIENT SIDE
var somelib = somelib || {};
somelib.queue = somelib.queue || [];
let pushObjectCorrect = { cmd: "someFunc1", args: "I am queeeued before the script is laoded" };
let pushObjectCorrect22 = { cmd: "someFunc1", args: "I am queeeued before the script is laoded" };
somelib.queue.push(pushObjectCorrect);
somelib.queue.push(pushObjectCorrect22);
const getParameterByName = function (name) {
const regexS = "[\\?&]" + name + "=([^&#]*)";
const regex = new RegExp(regexS);
const results = regex.exec(window.location.search);
if (results === null) {
return "";
}
return decodeURIComponent(results[1].replace(/\+/g, " "));
};
const creator = ({ variableHere = 'no', notHere = 'some-default' }) => {
let myObject = {
id: 'someId',
...(variableHere && { variableHere }),
...(notHere && { notHere }),
};
return myObject
}
let variableHere = 'yes'
service: functions
package:
individually: true
exclude:
- node_modules/aws-sdk/** #Its already included in the aws lambda environment
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules:
function insertPixel(params) {
const pixelUrl = `https://YOUR_DISTRIBUTION.cloudfront.net/1x1.png`;
const pixel = document.createElement("img");
pixel.setAttribute(
"src",
`${pixelUrl}${params}&someunique=${getRandomNumber()}`
);
pixel.setAttribute("height", "1");
pixel.setAttribute("width", "1");
document.body.appendChild(pixel);