Skip to content

Instantly share code, notes, and snippets.

View sanusart's full-sized avatar

Sasha Khamkov sanusart

View GitHub Profile
@sanusart
sanusart / color.js
Last active October 8, 2019 19:58
Light or dark hex color #color #hex
export const lightOrDark = (color, ratio = 155) => {
const hex = color.replace('#', '');
const red = parseInt(hex.substr(0, 2), 16);
const green = parseInt(hex.substr(2, 2), 16);
const blue = parseInt(hex.substr(4, 2), 16);
const brightness = (red * 299 + green * 587 + blue * 114) / 1000;
return brightness > ratio ? 'light' : 'dark';
};
"Redux forces you to write good code" - I've heard that sentence many times.
In fact - it's quite easy to write bad code with Redux, as I've seen many times.
In this talk I will show some bad practices and techniques with Redux, and how to avoid them.
@sanusart
sanusart / sortBy.pipe.ts
Last active January 12, 2018 19:06
Angular sortBy pipe #tag #angular #angular4 #lodash #fp #pipe #tag1
import { Pipe, PipeTransform } from '@angular/core';
import { sortBy, reverse, flow, identity } from 'lodash/fp';
@Pipe({ name: 'sortBy' })
export class SortByPipe implements PipeTransform {
transform(list, field, direction = 'DESC') {
return flow([
sortBy([field]),
@sanusart
sanusart / ObjRename.js
Last active July 14, 2019 11:40
Rename object key (deep object too) #lodashfp #fp #lodash #rename
const { flow, omit, head, set, at } = require("lodash/fp")
const object = {
id: 'CA1',
longName: 'The name',
status: 'open',
another1: 'value1',
another2: 'value2'
};
@sanusart
sanusart / lodash-fp-documentation.md
Created April 19, 2017 07:14 — forked from jfmengels/lodash-fp-documentation.md
Generated docs for Lodash/fp. Help make them better at https://github.com/jfmengels/lodash-fp-docs
@morsdyce
morsdyce / reactive2016_lightning_talk.md
Last active March 7, 2019 15:44
Introduction to BDSM - ReactiveConf Lightning talk proposal

This is a proposal for a ⚡lightning talk at the Reactive 2016 conference.

🌟Star this gist if you want to see it on the conference.

Introduction to BDSM

Every day we work with multiple teams to build our products, communication and sync are key factors to deliver your product on time without compromising quality.

In this talk I will introduce BDSM a new mocking tool that will change the way you coordinate between client and server teams minimizing friction allowing each team to work at its own pace while keeping in sync.

@sanusart
sanusart / String.prototype.js
Created May 14, 2016 22:29
Safe(r) String.prototype extend example #js #javascript
// String.prototype.repeat
// http://jsbin.com/sifesep/edit?js,console,output
Object.defineProperty(String.prototype, 'repeat', {
value: function debug_repeat(times, returnArray) {
var res = [];
var i = 0;
for (i; i < times; i++) {
res.push(this);
}
if (returnArray) {
@sanusart
sanusart / preserving-history.md
Last active January 27, 2018 16:58 — forked from dannyroberts/preserving-history.md
rename whole directories while preserving the git history #git

Did you know...

...that git lets you move and rename whole directories while preserving the git history of those files?

If you run

git read-tree --prefix=$NEW_PATH -u master:$OLD_PATH
rm -rf $OLD_PATH
# ...you probably want to change some imports...
git commit -m $MESSAGE