Skip to content

Instantly share code, notes, and snippets.

View DScheglov's full-sized avatar
🏠
Working from home

Dmytro Shchehlov DScheglov

🏠
Working from home
View GitHub Profile
@DScheglov
DScheglov / jsconfig.json
Last active August 18, 2020 19:32
/pages/jsconfig.json
{
"compilerOptions": {
"baseUrl": "..",
"paths": {
"@src/*": ["./src/*"]
}
}
}
@DScheglov
DScheglov / cloudSettings
Last active October 21, 2020 09:11
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-10-21T09:11:51.403Z","extensionVersion":"v3.4.3"}
export const amountToString = amount => (
amount < 0 ? `(${-amount})` : `${amount}`
);
[ ["Иван", "Иванов"],
[101101, "Московское ш., 101, кв. 101", "Ленинград"],
["812 123-1234", "916 123-4567"] ]
{ "firstName": "Иван", "lastName": "Иванов",
"address": { "streetAddress": "Московское ш., 101, кв. 101", "city": "Ленинград", "postalCode": 101101 },
"phoneNumbers": ["812 123-1234", "916 123-4567"] }
@DScheglov
DScheglov / resolvers.js
Last active March 29, 2020 11:10
dataLoaders
const authorsByIds = () => new DataLoader(async ids => {
const authors = await authorModel.findByIds(ids);
const authorById = new Map();
authors.forEach(author => authorById.set(author.id, author));
return ids.map(id => authorById.get(id));
});
const authorResolver = (source, { id }, context) => {
let dl = context.dataLoaders.get(authorsById);
if (!dl) {
@DScheglov
DScheglov / cloudSettings
Created January 11, 2020 12:45
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-01-11T12:45:39.616Z","extensionVersion":"v3.4.3"}
const normalize = (k, v) => (
k !== '' && Array.isArray(v)
? { name: v[0], age: v[1], flag: v[2] }
: v
);
const data = JSON.parse(
'[["name", 13, true], ["surname", 34, false]]',
normalize
);
function MapValues<K extends string, S, D>(
source: { [k in K]: S },
mapper: (value: S, key: K, src: { [k in K]: S }) => D
): { [k in K]: D } {
const dest = {} as { [k in K]: D };
for (let key of Object.keys(source) as K[]) {
dest[key] = mapper(source[key], key, source)
}
const get = items => index => items[index];
const push = items => item => { items.push(item); };
const pop = items => () => items.pop();
const arrayApi = items => Object.assign(
get(items), {
push: push(items),
pop: pop(items),
}
);