Skip to content

Instantly share code, notes, and snippets.

View RinatValiullov's full-sized avatar
👷‍♂️
Looking for a job

Rinat Valiullov RinatValiullov

👷‍♂️
Looking for a job
View GitHub Profile
@RinatValiullov
RinatValiullov / array_iteration_thoughts.md
Created March 5, 2017 12:34 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@RinatValiullov
RinatValiullov / angle-arrow-down.md
Last active June 25, 2017 20:43
Pure CSS Icons

HTML:

  <div class="wrapper">
    <div class="check icon"></div>
  </div>

CSS:

@RinatValiullov
RinatValiullov / Maximum.md
Last active June 25, 2017 20:37
Getting the maximum number
function checkNumbers(a, b, c) {
	if ( a > b ) {
	
		if ( a > c ) {
			console.log("maximum = " + a);
		} else {
			console.log("maximum = " + c);
		}
@RinatValiullov
RinatValiullov / closure.md
Last active June 30, 2017 04:18
Learn Closure (замыкание)
// Enclosing function (Внешняя (родительская) функция )
function numberGenerator() {
	var num; // локальная "свободная" переменная

	// Внутренняя (дочерняя) функция. Имеет доступ к переменной "num" благодаря замыканию
	function checkNumber(num) {
		num++; // Увеличиваем на единицу входящий параметр
		console.log(num); // Выводим в консоль
	}
var pow=  function (x, n){
  
  if( n !== 1 ) {
    return (x * pow(x, n-1));
  } else {
    return x;
  }
 
@RinatValiullov
RinatValiullov / what-forces-layout.md
Created October 21, 2017 21:44 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
let step = (base, exponent) => {
	exponent = exponent || 2;
	
	/* Ternary operator(other way):
	 * (exponent == undefined) ? exponent = 2 : exponent;
	 */
    
 let res = 1;
@RinatValiullov
RinatValiullov / convertHEX_to_RGB.js
Last active November 21, 2017 21:57
Convert Hexidecimal to RGB value(for colors)
let HEX_to_RGB = (hex) => {
let r = hex.substr(0,2),
g = hex.substr(2,2),
b = hex.substr(4,2);
return {
r: parseInt(r, 16),
g: parseInt(g, 16),
b: parseInt(b, 16)
@RinatValiullov
RinatValiullov / addSpaces.js
Last active November 21, 2017 22:15
Add spaces in string and deleted first blank (with regular expressions)
let addSpaces = (str) => {
str = str.replace(/([A-Z])/g, ' $1');
let removeInitBlank = () => {
return str.replace(/^\s/, '');
}
return removeInitBlank();
};
@RinatValiullov
RinatValiullov / list.js
Last active November 26, 2017 17:52
Function list(), which return an array from arguments
// #1 With spread operator (ES6 syntax). Verbose, but interesting
let list1 = function(...args) {
let array = [];
for(let i = 0, len = args.length; i < len; ++i) {
array.push(args[i]);
};
return array;
};
// #1.1 Amazing arrow functions and spread syntax