Skip to content

Instantly share code, notes, and snippets.

View vvscode's full-sized avatar
⌨️
Here is Rhodes, jump here!

Vasiliy Vanchuk vvscode

⌨️
Here is Rhodes, jump here!
View GitHub Profile
@vvscode
vvscode / onlyForAdmin.ng-directive.js
Created November 15, 2015 07:35
onlyForAdmin directive
angular
.module('smartjs').directive('onlyForAdmin', function(ngIfDirective) {
ngIfDirective = ngIfDirective[0];
return {
transclude: ngIfDirective.transclude,
priority: ngIfDirective.priority,
terminal: ngIfDirective.terminal,
restrict: ngIfDirective.restrict,
link: function($scope, $element, $attr) {
$attr.ngIf = 'user.isAdmin';
@vvscode
vvscode / onOutsideClick.ng-directive.js
Last active November 15, 2015 14:09
onOutsideClick
angular
.module('smartjs').directive('onOutsideClick', function($parse) {
return {
restrict: 'A',
link: function($scope, $element, $attr) {
var element = $element[0];
var fn = function() {
$scope.$eval($attr.onOutsideClick);
};
var onBodyClickHandler = function(ev) {
@vvscode
vvscode / vasiliy_elevator.js
Created March 15, 2016 18:47
Задача про лифт
var DIRECTION_DOWN = -1
var DIRECTION_NONE = 0
var DIRECTION_UP = 1
function HardwareElevator(){};
HardwareElevator.prototype = {
moveUp:function(){console.log('moving up');},
moveDown:function(){console.log('moving down');},
stopAndOpenDoors:function(){console.log('stopping and opening doors');},
getCurrentFloor:function(){console.log('getting current floor');},
@vvscode
vvscode / am-snippet.js
Created March 31, 2016 06:43
Amazing Hiring parsing helper
// In global NS to make debug more easier
var PAGES_DELAY = 3000;
var profiles = [];
function step1() {
console.log(`Process page: ${window.location}`);
$('a[href*="/profile"]').toArray().forEach((a) => profiles.push(a.getAttribute('href')));
console.log(profiles.length, $('a[href*="/profile"]').length);
if(!$('a.page-link.next').length) {
return;
@vvscode
vvscode / godmode.js
Created September 4, 2016 17:29
God Mode in JavaScript
// что возвращает эта функция?
(function fun(Infinity, length, __proto__)
{
return [,,~0.[0|0]][fun.__proto__.length && Infinity, -~String(this).length >> __proto__] << (0. === .0) + Infinity;
}).apply(typeof fun, [,,2]);
// рассмотрим массив с аргументами:
// "0" in [,,2] => false
// "1" in [,,2] => false

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () =&gt; x) {
const {
buildSquareStr
} = require('./buildSquareStr');
const assert = require('assert');
const SQUARES = {
1: `■`,
3: [`□□□`, `□■□`, `□□□`].join('\n'),
5: [`■■■■■`, `■□□□■`, `■□■□■`, `■□□□■`, `■■■■■`].join('\n'),
7: ['□□□□□□□', '□■■■■■□', '□■□□□■□', '□■□■□■□', '□■□□□■□', '□■■■■■□', '□□□□□□□'].join('\n'),
const {
getChange
} = require('./getChange');
const assert = require('assert');
const TESTS = [{
dealDetails: [1, 1],
change: [0, 0, 0, 0, 0, 0]
},
{
@vvscode
vvscode / package.json
Last active February 3, 2019 10:15
Websocket shell (node.js)
{
"name": "ws-proxy",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@vvscode
vvscode / News.d.ts
Created February 8, 2019 10:32
handle-api-call-state-nicely
export interface News {
loading: boolean;
entities: string[];
}