Skip to content

Instantly share code, notes, and snippets.

View a-x-'s full-sized avatar
🛩️

Alexander a-x-

🛩️
View GitHub Profile
@a-x-
a-x- / verify-image-file-signature.js
Created April 21, 2016 12:52
Upload images guard (MVG picture can show local files content: http://www.imagemagick.org/script/magick-vector-graphics.php).
// on input[type="file"]#change
var file = fileInput.files[0];
(function(){
var reader = new FileReader();
reader.onload = function(e) {
var view = new DataView(e.target.result),
// 0xFFD8 — jpeg file signature (filesignatures.net/?search=jpg&mode=EXT)
isPngSignature = view.getUint32(0, false) === 0x89504E47 && view.getUint32(4, false) === 0x0D0A1A0A,
// 0x 89 50 4E 47 0D 0A 1A 0A — png signature (filesignatures.net/?search=png&mode=EXT)
@a-x-
a-x- / worker-on-fly.js
Last active April 22, 2016 17:26
Javascript threads
var workerFunction = function() {
self.onmessage = function(e) {
self.postMessage('msg from worker' + e.data);
self.close();
};
};
var createWorker = fn => {
var workerFunctionBlob = new Blob(['('+fn.toString()+')()'], { type: "text/javascript" });
var worker = new Worker(URL.createObjectURL(workerFunctionBlob));
/**
* Дергает счетчик
*
* @param {String} url - Урл счетчика (без протокола!)
*/
makeReq: function(url) {
var createWorker = function(fn){
var workerFunctionBlob = new Blob(['('+fn.toString()+')()'], { type: "text/javascript" });
var worker = new Worker(URL.createObjectURL(workerFunctionBlob));
URL.revokeObjectURL(workerFunctionBlob); // free fake blob url
@a-x-
a-x- / worker-bemhtml.js
Created April 24, 2016 11:17
Parallel bemhtml client rendering in WebWorker Raw
// Begin: worker context function
var workerFunction = () => {
postMessage('bemhtml worker is ready');
// Begin: Standart bemhtml client code
// see worker code at file end
var BEMHTML;
(function(global) {
var buildBemXjst = function(exports, __bem_xjst_libs__){
@a-x-
a-x- / enumerate-files-which-use-i18n-and-nearest-i18n-dirs.js
Created May 17, 2016 12:42
Enumerate files which use i18n and nearest *.i18n/ dirs
'use strict';
require('shelljs/global');
const fs = require('then-fs');
const _ = require('lodash');
const Path = require('path');
const dirname = path => Path.dirname(path);
const basename = path => Path.basename(path);
const baseBemName = path => basename(path).match(/^[^.]+/)[0]; // without tech
@a-x-
a-x- / bemjson-testeditor-under-cursor-parser.js
Last active July 4, 2016 09:50
bementites parser for text editor plugin
/**
* @typedef {Object} PluralBemEntity
* @property {String} block
* @property {String} elem
* @property {Object} mods
* @property {Object} elemMods
*/
/**
* @typedef {Object} SingleBemEntity
@a-x-
a-x- / bem-tools.spec.md
Last active February 6, 2017 19:31
BEM Tools specification draft
@a-x-
a-x- / sample.json5
Last active July 15, 2016 19:49
test json5
{
key: 'val', // JSON5 Yay
fooMultiline: 'what you doing?\
ahah, stoop',
"oldschool": "fdfsd", /* trailing comma */
}
@a-x-
a-x- / ValOp.md
Last active July 30, 2016 16:27
Operations on maybe types transport

https://twitter.com/mxtnr/status/759409328956776448

Родилась интересная концепция, которая лучше всего может заработать в ФП-языках (но применимо и в таких языках как js).

Пример: есть блок popup2 с параметром mainOffset и дефолтным значением 5, если задан параметр theme=normal, иначе 0

И есть блок tooltip, который композируются над popup2.
Если задан параметр блока tooltip tail: false, он увеличивает mainOffset на 5 Но если mainOffset не задан, то tooltip не знает, что делать.

@a-x-
a-x- / .jshint-groups.js
Last active August 4, 2016 19:22
jshint configs
// Шаблоны для поиска файлов определённой технологии.
// Используется для includes/excludes в jshint-groups.
var files = {
all: [
'**/*.i18n/*.js'
],
bemdecl: [
'pages-*/**/common.bemdecl.js'
],
testPriv: [