Skip to content

Instantly share code, notes, and snippets.

View arturparkhisenko's full-sized avatar
:octocat:
www. www always changes

Artur Parkhisenko arturparkhisenko

:octocat:
www. www always changes
View GitHub Profile
@arturparkhisenko
arturparkhisenko / js-hints-object.js
Last active October 27, 2017 20:10
js-hints-object
// https://www.youtube.com/watch?v=5Kw4XVSb4P4
// Cloning objects, not deep! use clone for that https://gist.github.com/arturparkhisenko/db604e314ea8ff8ba065
const clonedR = {...obj};
const cloneOS = Object.assign({}, obj);
// Merging objects (also filling with defaults)
const mergedR = {...obj1, ...obj2};
const mergedOS = Object.assign({}, obj1, obj2);
@arturparkhisenko
arturparkhisenko / css-linting-html.css
Last active August 23, 2017 19:52
css linting html
/* source: https://bitsofco.de/linting-html-using-css/ */
/* colors */
:root {
--color-info: #5bc0de;
--color-warning: #f0ad4e;
--color-danger: #d9534f;
}
/* Inline Styles */
*[style] {
border: 5px solid var(--color-warning);
@arturparkhisenko
arturparkhisenko / js-sum-without-a-plus.js
Created February 25, 2017 21:16
js-sum-without-a-plus
/**
* @param {number} a
* @param {number} b
* @return {number}
*/
var getSum = function(a, b) {
var result = a;
var rest = b;
while (rest) {
var carry = result & rest; // and (to get carry value: 0 || 1)
@arturparkhisenko
arturparkhisenko / xfill-meaning.md
Created December 14, 2016 18:09
xfill-meaning, polyfill, prollyfill, nottifill, ponyfill

// source: jonathantneal/document-promises#4 (comment)

  • Polyfill: functionality current systems implement natively.
  • Prollyfill: functionality future systems expect to implement natively, as defined by widely accepted specifications.
  • Nottifill: functionality future systems may implement natively, as desired by developers.
  • Ponyfill: a strategy where functionality is implemented as an independent module.
@arturparkhisenko
arturparkhisenko / js-css-modern-node-set-props.js
Created November 7, 2016 19:41
js-css-modern-node-set-props
// https://twitter.com/forwebdev/status/795342853295734784
const p = document.querySelector('p');
// old method
p.style.margin = '1rem';
p.style.color = 'green';
// new method
Object.assign(p.style, {
/* https://benfrain.com/a-modern-css-reset-with-caveats/ */
* {
all: unset;
}
/* Thanks to L. David Baron for this: https://twitter.com/davidbaron/status/794138427952222210 */
base, basefont, datalist, head, meta, script, style, title, noembed, param, template {
display: none;
}
@arturparkhisenko
arturparkhisenko / .profile
Created November 4, 2016 19:01 — forked from sindresorhus/.profile
Automatic Git commit signing with GPG on OSX
# In order for gpg to find gpg-agent, gpg-agent must be running, and there must be an env
# variable pointing GPG to the gpg-agent socket. This little script, which must be sourced
# in your shell's init script (ie, .bash_profile, .zshrc, whatever), will either start
# gpg-agent or set up the GPG_AGENT_INFO variable if it's already running.
# Add the following to your shell init to set up gpg-agent automatically for every shell
if [ -f ~/.gnupg/.gpg-agent-info ] && [ -n "$(pgrep gpg-agent)" ]; then
source ~/.gnupg/.gpg-agent-info
export GPG_AGENT_INFO
else
var regex = /^((http|https)://)?[\w\.]+\.\w{2,5}$/;
@arturparkhisenko
arturparkhisenko / js-search-and-reduce.js
Last active October 21, 2016 21:18
js-search-and-reduce
// https://twitter.com/forwebdev/status/789538916898660352
const userIds = [1, 5, 1, 2, 9, 9, 6, 4, 3, 5];
console.log(userIds.slice().sort();
// -> [1, 1, 2, 3, 4, 5, 5, 6, 9, 9]
function getUniqueItems(array) {
const = uniqueItemsHash = array.reduce((acc, item) => {
acc[item] = item;
return acc;
}, {});
@arturparkhisenko
arturparkhisenko / js-reduce-vs-filter-and-map.js
Created October 7, 2016 18:45
js-reduce-vs-filter-and-map, Use reduce instead of chains map and filter, to reduce the number of repeated passes through the array
// https://twitter.com/forwebdev/status/782844763942817792
const users = [{
firstName: 'John',
lastName: 'Black',
age: 27
}, ...];
// bad, two passes
users