Skip to content

Instantly share code, notes, and snippets.

View Emilios1995's full-sized avatar

Emilio Srougo Emilios1995

View GitHub Profile
const validationRules = {
notificationsClientId: [
[
dep("getsNotifications", R.equals(true), isType("String")),
"If getsNotifications is true, notificationsClientId is required as a string"
]
]
}
const optionalTypeRule = type => [
unlessNil(isType(type)),
(val, field) => `if ${field} is set, it must be a ${type}`
];
const validationRules = {
appDescription: [optionalTypeRule('String')]
}
const normalize = (spec, input) =>
Object.keys(spec).reduce(
(acc, x) => R.assoc(x, R.propOr(null, x, input), acc),
{}
);
const normalize = (spec, input) =>
Object.keys(spec).reduce(
(acc, x) => R.assoc(x, R.propOr(null, x, input), acc),
{}
);
const typeMessage = (type, field) => `${field} has to be a ${type}`;
const typeRule = type => [
isType(type),
(val, field) => typeMessage(type, field)
];
const isString = typeRule("String");
const isNumber = typeRule("Number")
const rules = {
version: [isNumber],
const isType = R.curry((type, value) => R.type(value) === type);
const rules = {
version: [[isType('Number')], 'Version must be a number'],
build: [[isType('Number')], 'Build must be a number'],
appName: [[isType('String'), 'appName must be a string']]
}
const concatMany = unapply(unnest)
concatMany([1,2,3], [4,5,6], [7,8,9])
// -> [1, 2, 3, 4, 5, 6, 7, 8, 9]
// updateKeys :: (String -> String) -> Object -> Object
const updateKeys = f =>
R.compose(R.fromPairs, R.map(R.over(R.lensIndex(0), f)), R.toPairs);
// updateKeysWithMap :: Object -> Object -> Object
const updateKeysWithMap = map => updateKeys(k => map[k] || k);
// example:
updateKeysWithMap({ oldKey: "newKey" })({ oldKey: 2 }); // -> { newKey: 2 }
sendNotification = function(data) {
var headers = {
"Content-Type": "application/json; charset=utf-8",
Authorization: "Basic NzkwODdjM2YtODMxNi00ODMyLTgwMWEtZTVkOTcyMzg4ZWRi"
};
var options = {
host: "onesignal.com",
port: 443,
path: "/api/v1/notifications",
// This goes after https://gist.github.com/DrBoolean/3f5ac08a5bf1c4673757
const setNameActionCretor = name => ({ type: "SET_NAME", payload: { name } });
const setName = localStorage
.chain(ls => safeProp("user", ls))
.chain(u => safeProp("name", u))
.map(n => n.toUpperCase())
.chain(printLn)
.map(m => m.toLowerCase())