Skip to content

Instantly share code, notes, and snippets.

@everdimension
everdimension / graphql-example.js
Created October 10, 2017 15:56
simplified graphql explanation
// Say we need to display list of posts showing *only* their titles
// and name of the post author
// without graphql
const data = {
posts: null,
usersById: {},
};
get('/api/posts')
@everdimension
everdimension / git-cleanup-approaches.md
Created April 17, 2019 12:31
Different git branch cleanup approaches

Cleanup merged branches

Source: https://stackoverflow.com/a/6127884/3523645

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

Cleanup orphaned branches

Problem: If pull-request are merged into the main branch using a "squash" strategy and then the remote branches are removed,

@everdimension
everdimension / git-rebase-onto.sh
Created May 20, 2020 17:23
"git rebase --onto" — used to rebase only latest (or several latest) commits onto a new branch
# This is just a note to self
git rebase --onto <base-branch> <current-branch>~ <current-branch>
# e.g. git rebase --onto master feature/something~ feature/something
# it's important here to use branch name and not other commit id.
# Can't use "HEAD" instead of "feature/something" ¯\_(ツ)_/¯
@everdimension
everdimension / gist:590395dd20831f9a787101c4c3084085
Created May 20, 2020 17:23
"git rebase --onto" — used to rebase only latest (or several latest) commits onto a new branch
# This is just a note to self
git rebase --onto <base-branch> <current-branch>~ <current-branch>
# e.g. git rebase --onto master feature/something~ feature/something
# it's important here to use branch name and not other commit id.
# Can't use "HEAD" instead of "feature/something" ¯\_(ツ)_/¯
@everdimension
everdimension / form-input-parsing.js
Last active April 14, 2020 04:40
Custom input parsing on form submit.
import React from 'react';
const inputParsers = {
date(input) {
const [month, day, year] = input.split('/');
return `${year}-${month}-${day}`;
},
uppercase(input) {
return input.toUpperCase();
},
@everdimension
everdimension / es6_classes.js
Last active March 5, 2020 07:59
Explanation of ecmascript 6 (ES2015) classes, class inheritance, super calls and static methods. Compiled online on babel site: https://goo.gl/vfdkpC
class BaseClass {
constructor(name, age) {
this.name = name;
this.age = age;
}
static getDescription() {
return "this function can be called without instantiating BaseClass";
}
getData() {
return ["base data is:", this.name, this.age].join(' ');
@everdimension
everdimension / collect-html-form-errors.js
Created July 31, 2019 16:49
Collect all errors of an html form. The "errors" object can be serialized.
/**
* Considering that each html input
* has a "name" attribute and proper
* validation attributes (type, pattern, required, etc)
* we collect "validity" states of invalid inputs
* and the "validationMessage" provided by the browsers
*/
const errors = Array.from(form.elements)
.filter((el) => el.hasAttribute('name'))
.reduce((acc, el) => {
@everdimension
everdimension / collect_form_data.js
Created March 17, 2017 11:22
A way to collect form data without `FormData` api.
handleSubmit(event) {
const form = event.target;
const data = {}
for (let element of form.elements) {
if (element.tagName === 'BUTTON') { continue; }
data[element.name] = element.value;
}
}
class MyForm extends React.Component {
constructor() {
super();
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event) {
event.preventDefault();
const data = new FormData(event.target);
@everdimension
everdimension / sequential-polling.ts
Last active April 19, 2019 13:39
Polling: "make request — wait for response, but no less than 1 second — make another request"
export function sequentialPolling({
taskFn,
interval = 1000,
}: {
taskFn: () => Promise<any>;
interval?: number;
}) {
let isActive = true;
let timeoutId: number | undefined;
let rejector: Function | undefined;