Skip to content

Instantly share code, notes, and snippets.

💭
I maintain OSS projects at nights, am available GMT+3 from 9pm to 1am

beraliv Beraliv

💭
I maintain OSS projects at nights, am available GMT+3 from 9pm to 1am
Block or report user

Report or block Beraliv

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Beraliv
Beraliv / all-permutations.js
Created Nov 3, 2019
Find all permutations for a specified string
View all-permutations.js
/**
* Traverse permutation to add new letter to every new position
*
* @example
* generateNextPermutation(['a','b'],'c')
* // => [['c','a','b'],['a','c','b'],['a','b','c']]
*/
function generateNextPermutation(permutation, ch) {
const destination = [];
for (let i = 0; i <= permutation.length; i++) {
View transducer-api-transducers-v2.js
import { filterT, map, mapT, pipeT, takeT, transduce, where } from 'nanoutils';
const isEven = value => value % 2 === 0;
const filterPredicates = {
name: ({ author }) => name => author === undefined || name === author,
timestamp: ({ from, to }) => timestamp =>
from === undefined ||
to === undefined ||
(from <= timestamp && timestamp <= to)
View debug-transducer.js
function debugT() {
return function(reducer) {
return function(acc, v) {
debugger;
return reducer(acc, v);
};
};
}
View console-transducer.js
function consoleT() {
return function(reducer) {
return function(acc, v) {
console.log(acc, v);
return reducer(acc, v);
};
};
}
View transducer-api-array-filter-every-slice-v2.js
const isEven = value => value % 2 === 0;
const filterPredicates = {
// if available, checks if names equal
author: ({ name }, { author }) => author === undefined || name === author,
// if available, checks if date starts from a specified value
from: ({ timestamp }, { from }) => from === undefined || from <= timestamp,
// if available, checks if date ends with a specified value
to: ({ timestamp }, { to }) => to === undefined || timestamp <= to
};
View transducer-api-core-js-2.js
const isEven = value => value % 2 === 0;
const isFilteredAuthor = ({ name }, { author }) => {
// if filter is not available, value is not filtered
if (author === undefined) {
return true;
}
// checks if names equal
return name === author;
};
View transducer-api-transducers.js
import { add, filterT, mapT, pipeT, transduce } from 'nanoutils';
const isEven = value => value % 2 === 0;
const transducers = array => {
const transducer = pipeT(
// transforms value to value + 1
mapT(add(1)),
// ignores odd values
filterT(isEven),
View transducer-api-array-map-filter-reduce.js
const isEven = value => value % 2 === 0;
const mapFilterReduce = array =>
// gets values from array
array
// transforms value to value + 1
.map(value => value + 1)
// ignores odd values
.filter(isEven)
// applies addition
View transducer-api-core-js.js
const isEven = value => value % 2 === 0;
const coreJs = array => {
// starts from 0
let sum = 0;
// iterates over array
for (let i = 0; i < array.length; i++) {
// transforms value to value + 1
const result = array[i] + 1;
// ignores odd values
@Beraliv
Beraliv / tutorial.md
Created Aug 16, 2018 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API
View tutorial.md

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.

You can’t perform that action at this time.