Skip to content

Instantly share code, notes, and snippets.

View probil's full-sized avatar
:shipit:
Exploring

Max Liashuk probil

:shipit:
Exploring
View GitHub Profile
"use strict";
const LEFT = 'left';
const RIGHT = 'right';
/**
* Calculates sign based on direction
* @param {string} direction
* @returns {Number}
*/
@probil
probil / validator.js
Created March 27, 2017 21:38
Is AlphaNumberic (JS)
export function isAlphaNumeric( value ) {
return /^[a-zA-Z0-9]+$/.test(value)
}
@probil
probil / ipv4.test.js
Created April 3, 2017 08:55
ipv4.test.js
it('Should return true for correct ipv4', () => {
let correctIps = [
'0.0.0.0/0',
'255.255.255.255/32',
'159.12.101.0/24'
];
let expected = {}
correctIps.map(ip => {
actual[ip] = true;
{
IPv4: /^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/
IPv6:/^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i,
}
@probil
probil / plugin-api-docs.js
Last active June 14, 2017 09:54
Store `hapi-swagger` auth key in `localStorage`
const HapiSwagger = require('hapi-swagger');
const config = require('../utils/config');
const swaggerOptions = {
basePath : `/api/${config.service.apiversion}/`,
jsonEditor : true,
documentationPath : '/api/docs',
swaggerUIPath : '/api/docs/swaggerui/',
jsonPath : '/api/docs/swagger.json',
securityDefinitions: {
const acorn = require("acorn")
const walk = require("acorn/dist/walk")
var getTarget = function (field, st, cb) {
// next lets see its an identifier, if so, its right on one of the state objects
var isId = field.type == 'Identifier';
var name = field.name;
var value, obj, prop;
@probil
probil / main.js
Created May 17, 2018 13:30
Example of socket.io server for #67
'use strict';
const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http, { serveClient: false });
const middleware = require('socketio-wildcard')();
io.use(middleware);
app.use((req, res, next) => {
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
server.listen(3000);
io.on('connection', function(socket){
console.log("---------------------------------------------------------")
console.log('An user connected');
@probil
probil / 10-emoji.conf
Last active June 24, 2018 10:00
Enable Color Emoji for Linux (any program, including browsers and terminal)
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match>
<test name="family"><string>monospace</string></test>
<edit name="family" mode="prepend" binding="weak">
<string>Noto Color Emoji</string>
</edit>
</match>
<match>
@probil
probil / main.mjs
Created June 24, 2018 16:53
Simple implementation of Vue reactivity system (computed properties)
import makeReactive from './makeReactive';
let data = {
data: {
price: 5,
quantity: 2
},
computed: {
total() {
return this.price * this.quantity