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
@probil
probil / is-minified.js
Created December 9, 2021 11:00
A small function to determine minification of the JavaScript file. Borrowed from Chrome DevTools
// https://github.com/ChromeDevTools/devtools-frontend/blob/0dc36933e485a7009c380f41564848d70cafb429/front_end/models/text_utils/TextUtils.ts#L336
export function isMinified(text) {
const kMaxNonMinifiedLength = 500;
let linesToCheck = 10;
let lastPosition = 0;
do {
let eolIndex = text.indexOf('\n', lastPosition);
if (eolIndex < 0) {
eolIndex = text.length;
@probil
probil / importAsToDoToHabitica.js
Last active May 4, 2019 11:04
Habitica: Import as TODO
//
// This scipts allows to import Egghead course as TODO to Habitica
//
// Step 1: Replace `apiKey` and `userId` with yours (check profile settings on Habitica)
// Step 2: Type resource name (egghead/vuemaster/frontendmaster/pluralsight/freecodecamp) in last line of the script
// Step 3: Open desired course in browser
// Step 4: Open DevTool and execute script in console
// Step 5: Check Habitica: new ToDo should be there :)
@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
@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>
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 / 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 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 / 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: {
{
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 / 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;