Skip to content

Instantly share code, notes, and snippets.

Avatar
👷‍♂️
looking for a job

Rinat Valiullov RinatValiullov

👷‍♂️
looking for a job
View GitHub Profile
@RinatValiullov
RinatValiullov / binarySearch.js
Last active Dec 8, 2017
Binary Search Algorithm
View binarySearch.js
/* 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 Dec 11, 2017
Instead of generators in ES6(Douglas Crockford's pattern). Returns next element of the array each time when generator inner function invokes.
View factoryFunction.js
// 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 Jan 18, 2018
Return random element of an array
View randomElement.js
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 Jan 19, 2018
Create array with generated random values (iterator)
View arrayWithRandValues.js
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 Jan 21, 2018
Get an attribute "class" of any object
View getClassOfObject.js
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 Feb 5, 2018 — forked from glebcha/gulpfile.js
Gulp task sample (css and js minify+concat, compress images, watching for changes)
View gulpfile.js
// Определяем зависимости в переменных
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 Feb 10, 2018 — forked from demisx/gulpfile.js
Gulp 4 gulpfile.js
View 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 Feb 18, 2018
Navigation Timing API
View CRP.html
<!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 Feb 21, 2018
Find biggest number with reduce
View FindBiggestNumber.md
// 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;
View !readme.md

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