Skip to content

Instantly share code, notes, and snippets.

View srgg6701's full-sized avatar

Сергей srgg6701

View GitHub Profile
@srgg6701
srgg6701 / search-autocompletion.js
Created August 15, 2018 07:39
A component intended to implement autocompletion in the search field
function walkCollection(elements, callback){
Array.prototype.forEach.call(elements, element => callback(element));
}
class SearchData {
constructor() {
const searchBarId = '#search-bar';
const form = document.querySelector(`${searchBarId} > form`);
const button = form.querySelector('button');
const storedSearchesBlock = document.querySelector('.stored-searches');
// traverses through object's own properties on all its levels
function walk (obj){
//
Object.keys(obj).forEach(function(ob){
var currentOb = obj[ob];
(Object.prototype.toString.call(currentOb)==='[object Object]')
? walk(currentOb)
: console.log('value', currentOb);
});
}
const isMobile = (typeof window.orientation !== "undefined" || navigator.userAgent.indexOf('IEMobile') !== -1);
@srgg6701
srgg6701 / setObjectStructure.js
Last active September 6, 2017 11:50
Create folded object taking property names from array
+function setObjectStructure(obj, index = 0, arr = ['one', 'two', 'three']){
obj[arr[index]] = {};
let nextIndex = index + 1;
if (arr.length > nextIndex){
setObjectStructure(obj[arr[index]], nextIndex, arr);
}
console.log('obj=>', obj);
}({});
@srgg6701
srgg6701 / build.js
Last active August 20, 2017 12:38
node walk dir
console.log('build here');
var fs = require('fs');
// var path = require('path');
var done = function(err) {
console.log(err);
}
// var file = path.resolve(dir, file);
console.log('__dirname=>', __dirname);
@srgg6701
srgg6701 / node-server.js ES5
Last active June 26, 2017 12:32
Node.js server in ES5 syntax
var http = require('http'),
fs = require('fs'),
port = 8080,
index_path = '/index.html';
http.createServer(function (request, response) {
var exts,
ext,
type = 'text';
@srgg6701
srgg6701 / nextInObject.js
Last active May 2, 2016 14:19
The iterator for the object. If there is the next element in the loop, returns current and next ones.
var elements,
nextInObject = (function(){
var i= 0, keys;
return function(obj){
if(!i) keys = Object.keys(obj);
if(obj[keys[i+1]]){
i++;
return [ [keys[i-1], obj[keys[i-1]]], [keys[i], obj[keys[i]]] ];
}else{
i=0;
@srgg6701
srgg6701 / nextInArray.js
Last active May 2, 2016 14:20
The iterator for the array. If there is the next element in the loop, returns current and next ones.
var elements,
nextInArray = (function(){
var i= 0;
return function(arr){
if(arr[i+1]){
i++;
return [arr[i-1], arr[i]];
}else{
i=0;
return false;
@srgg6701
srgg6701 / karma.conf.js
Last active April 28, 2016 12:27
Working minimal set for running jasmine/karma test in WebStorm. Locally installed: karma, karma-jasmine In order to run tests from command line is necessary to instal karma-cli globally. Then run command: > karma start [path/]karma.comf.js
// Karma configuration
// Generated on Sun Jul 20 2014 11:36:55 GMT+0400 (Московское время (зима))
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
//basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser