Skip to content

Instantly share code, notes, and snippets.

View slavafomin's full-sized avatar
✌️
Let's make this World a better place!

Slava slavafomin

✌️
Let's make this World a better place!
View GitHub Profile
@slavafomin
slavafomin / javascript-pluralization.md
Last active February 12, 2023 19:22
How to pluralize words in JavaScript in different languages?

How to pluralize any word in different languages using JavaScript?

Hello!

Today, I'm going to show you how to pluralize any word in JavaScript (Node.js or Browser) in almost any language!

I've developed a very simple, but powerful package in JavaScript that will help you to achieve this goal. It's called Numerous.

@slavafomin
slavafomin / nodejs-custom-es6-errors.md
Last active November 14, 2024 11:23
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/AppError.js

@slavafomin
slavafomin / 0-install-nodejs-v9.sh
Last active June 19, 2018 08:20
Install latest version of Node.js in Ubuntu using bash shell script
#/usr/bin/env bash
set -o errexit
set -o pipefail
NODE_VERSION="v9"
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
. $HOME/.nvm/nvm.sh
@slavafomin
slavafomin / install-phpstorm.sh
Last active September 29, 2017 12:04
Bash shell script to install PhpStorm automatically
#!/usr/bin/env bash
# @todo: load URL from here: https://data.services.jetbrains.com/products/releases?code=PS&latest=true&type=release
set -o errexit
set -o pipefail
shopt -s nullglob
DROPBOX_PATH="$HOME/Dropbox"
INSTALL_PATH="$HOME/PhpStorm"
@slavafomin
slavafomin / install-telegram.sh
Last active June 2, 2017 15:40
Install Telegram on Ubuntu using shell automatically
#/usr/bin/env bash
set -o errexit
set -o pipefail
shopt -s nullglob
INSTALL_PATH="$HOME/Telegram"
TEMP_PATH="$HOME/.tmp"
sudo apt-get install xz-utils
@slavafomin
slavafomin / 0-README.md
Last active January 19, 2016 11:24
Angular.js Directive for Vimeo Player
@slavafomin
slavafomin / Gulp-JavaScript-Resolve-Dependencies.md
Last active February 11, 2016 15:12
Gulp JavaScript Resolve Dependencies

Gulp JavaScript Resolve Dependencies

This Gulp task will resolve JavaScript dependencies and build individual bundles.

Install pre-requisites:

npm i --save-dev gulp gulp-resolve-dependencies gulp-uglify gulp-if gulp-foreach

Specify dependencies in your files:

@slavafomin
slavafomin / 0-readme.md
Last active April 4, 2020 04:29
Loop promises in Angular.js / Run list of actions sequantually

The provided example will allow you to do sequential requests to the server in Angular.js.

It will iterate all the items and call server for each item, however, if one request will fail, all sequential requests will be aborted.

If you need to call all requests no matter what, just replace promise.then() with promise.finally().

Cheers!

@slavafomin
slavafomin / ForcedLogoutListener.php
Last active September 4, 2022 17:59
Logging user out of Symfony 2 application using kernel event listener
<?php
namespace App\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@slavafomin
slavafomin / 0-success-list.json
Last active August 29, 2015 14:04
JSON server response example
{
"success": true,
"data": [
{
"id": 1,
"title": "Foo"
},
{
"id": 2,
"title": "Bar"