Skip to content

Instantly share code, notes, and snippets.

View znechai's full-sized avatar

Eugene Nechai znechai

  • Belarus, Minsk
View GitHub Profile
function methodThatReturnsAPromise ( id ) {
return new Promise( ( resolve, reject ) => {
setTimeout( () => {
console.log( `Processing ${ id }` );
resolve( id );
}, 1000 );
} );
}
let result = [ 1, 2, 3 ].reduce( async ( accumulatorPromise, nextID ) => {
@znechai
znechai / angular-device-detector-factory.js
Last active April 1, 2017 19:50
Angular - Device Detector Factory
function useragent($q, $window) {
return {
// Get user agent
getUserAgent: function () {
var deffered = $q.defer();
if ($window.navigator && $window.navigator.userAgent){
var ua = $window.navigator.userAgent;
deffered.resolve(ua);
}
@znechai
znechai / angular-socket-factory.js
Last active April 1, 2017 19:51
Angularjs - Factory for Socket.io
function socket($rootScope) {
var socket = io.connect('https://HOST:PORT');
return {
emit: function (eventName, data, callback) {
socket.emit(eventName, data, function () {
var args = arguments;
$rootScope.$apply(function () {
if (callback) {
callback.apply(socket, args);
@znechai
znechai / nginx.conf
Last active April 6, 2017 15:53
Nginx - nginx virtual server+
server {
listen 80;
root /var/www/HOST/;
index index.php index.html;
server_name HOST.com www.HOST.com;
return 301 $scheme://HOST.by$request_uri;
autoindex off;
charset utf-8;
server_tokens off;
@znechai
znechai / pluralize-ru.js
Last active April 2, 2024 03:03
JavaScript - Plural forms for russian words
/**
* Plural forms for russian words
* @param {Integer} count quantity for word
* @param {Array} words Array of words. Example: ['депутат', 'депутата', 'депутатов'], ['коментарий', 'коментария', 'комментариев']
* @return {String} Count + plural form for word
*/
function pluralize(count, words) {
var cases = [2, 0, 1, 1, 1, 2];
return count + ' ' + words[ (count % 100 > 4 && count % 100 < 20) ? 2 : cases[ Math.min(count % 10, 5)] ];
}