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 / binarySearch.js
Last active December 8, 2017 10:44
Binary Search Algorithm
/* We can only use binary search if the input array of numbers is already sorted! */
let binarySearch = (target, numbers) => {
/* find an apearance of target in numbers */
/*
** we have lowLimit and highLimit of our range(numbers)
** so starting point is -1 (the 0th index)
*/
let lowLimit = -1;
@RinatValiullov
RinatValiullov / factoryFunction.js
Last active December 11, 2017 09:30
Instead of generators in ES6(Douglas Crockford's pattern). Returns next element of the array each time when generator inner function invokes.
// Simple array
const myArray = [4,5,6];
const factoryFunction = (array) => {
// The generator's state variable(s)
let i = 0;
return function generator() {
if(i < array.length) {
// Compute the new value
@RinatValiullov
RinatValiullov / randomElement.js
Created January 18, 2018 20:03
Return random element of an array
function randEl( array ) {
return array[Math.round(Math.random() * (array.length - 1))]
};
const myArray = [1,2,3,4,5,6,7,8,9];
randEl( myArray ); // random element of an myArray
@RinatValiullov
RinatValiullov / arrayWithRandValues.js
Created January 19, 2018 17:19
Create array with generated random values (iterator)
let randoms = {
[Symbol.iterator]: function() {
return {
next: function() {
// Generate values in range [0..10]
return { value: Math.round(Math.random() * 10) };
}
};
}
};
@RinatValiullov
RinatValiullov / getClassOfObject.js
Last active January 21, 2018 19:12
Get an attribute "class" of any object
function getClassOfObject( object ) {
if ( object === null ) return "Null";
if ( object === undefined ) return "Undefined";
return Object.prototype.toString.call( object ).slice(8, -1);
};
getClassOfObject(null) // "Null"
getClassOfObject('string') // "String"
getClassOfObject(111) // "Number"
getClassOfObject(Object.constructor) // "Function"
@RinatValiullov
RinatValiullov / gulpfile.js
Created February 5, 2018 12:43 — forked from glebcha/gulpfile.js
Gulp task sample (css and js minify+concat, compress images, watching for changes)
// Определяем зависимости в переменных
var gulp = require('gulp'),
cache = require('gulp-cache'),
clean = require('gulp-clean'),
stream = require('event-stream'),
size = require('gulp-size'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
minifyCSS = require('gulp-minify-css'),
@RinatValiullov
RinatValiullov / gulpfile.js
Created February 10, 2018 06:55 — forked from demisx/gulpfile.js
Gulp 4 gulpfile.js
// Gulp 4
var gulp = require('gulp');
var using = require('gulp-using');
var grep = require('gulp-grep');
var changed = require('gulp-changed');
var del = require('del');
var coffee = require('gulp-coffee');
var less = require('gulp-less');
var coffeelint = require('gulp-coffeelint');
var sourcemaps = require('gulp-sourcemaps');
@RinatValiullov
RinatValiullov / CRP.html
Created February 18, 2018 18:22
Navigation Timing API
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Measuring the Critical Rendering Path</title>
<link rel="stylesheet" href="./style.css">
<script src="./script.js" defer></script>
</head>
@RinatValiullov
RinatValiullov / FindBiggestNumber.md
Last active February 21, 2018 17:50
Find biggest number with reduce
// e. g. let's take some array of numbers
let numbers = [11,55,2,98,115,32,116,48,154];

let biggest = numbers.reduce( (acc, curr) => {
    console.table({acc, curr});
    return curr > acc ? curr : acc;
});

// console.log(biggest); the biggest number will be 154;
@RinatValiullov
RinatValiullov / !readme.md
Created February 21, 2018 18:46
ST3 sync settings

Синхронизация настроек Sublime Text 3