Skip to content

Instantly share code, notes, and snippets.

@everdimension
everdimension / graphql-example.js
Created Oct 10, 2017
simplified graphql explanation
View graphql-example.js
// 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 / formdata.appenObject.js
Created Oct 26, 2015
Append nested object to FormData. The object can be just one level deep. For anything more complex it is recommended to rethink the way you send such data to the server.
View formdata.appenObject.js
(function() {
'use strict';
if (window.FormData) {
FormData.prototype.appendObject = function (obj, namespace) {
// EXAMPLE:
// var person = { name: 'some name', age: 87 };
// var fd = new FormData();
// fd.appenObject(obj, 'person');
@everdimension
everdimension / git-cleanup-approaches.md
Created Apr 17, 2019
Different git branch cleanup approaches
View git-cleanup-approaches.md

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
"git rebase --onto" — used to rebase only latest (or several latest) commits onto a new branch
View git-rebase-onto.sh
# 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
"git rebase --onto" — used to rebase only latest (or several latest) commits onto a new branch
View gist:590395dd20831f9a787101c4c3084085
# 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 Apr 14, 2020
Custom input parsing on form submit.
View form-input-parsing.js
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 Mar 5, 2020
Explanation of ecmascript 6 (ES2015) classes, class inheritance, super calls and static methods. Compiled online on babel site: https://goo.gl/vfdkpC
View es6_classes.js
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 Jul 31, 2019
Collect all errors of an html form. The "errors" object can be serialized.
View collect-html-form-errors.js
/**
* 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 Mar 17, 2017
A way to collect form data without `FormData` api.
View collect_form_data.js
handleSubmit(event) {
const form = event.target;
const data = {}
for (let element of form.elements) {
if (element.tagName === 'BUTTON') { continue; }
data[element.name] = element.value;
}
}
View minimal-react-form.js
class MyForm extends React.Component {
constructor() {
super();
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event) {
event.preventDefault();
const data = new FormData(event.target);