Skip to content

Instantly share code, notes, and snippets.

View wmakeev's full-sized avatar
💭
💻

Makeev Vitaliy wmakeev

💭
💻
View GitHub Profile
@wmakeev
wmakeev / mutation-observer.js
Last active August 29, 2015 14:14
MutationObserver
// https://developer.mozilla.org/en/docs/Web/API/MutationObserver
// create an observer instance
var observer = new MutationObserver(function(mutations) {
console.log(mutations);
});
// configuration of the observer:
var config = {
attributes: true,
// Start off with a promise that always resolves
var sequence = Promise.resolve();
// Loop through our chapter urls
story.chapterUrls.forEach(function(chapterUrl) {
// Add these actions to the end of the sequence
sequence = sequence.then(function() {
return getJSON(chapterUrl);
}).then(function(chapter) {
addHtmlToPage(chapter.html);
@wmakeev
wmakeev / npm_install.js
Created February 6, 2015 09:52
npm API
var npm = require('npm');
var pkg = require('../package');
npm.load(pkg, function (err) {
if (err) throw err;
npm.commands.install(['have'], function (err) {
if (err) throw err;
console.log('Packages installed');
});
});
@wmakeev
wmakeev / origins.makefile
Last active August 29, 2015 14:15
Several origins
# http://habrahabr.ru/post/250645/
# rename origin remote
git remote rename origin github
# add the gitlab remote (for the love of everything that’s holy, use ssh)
git remote add bitbucket <remote link for bitbucket>
# push existing code to new remote
git push -u bitbucket —all
@wmakeev
wmakeev / gulpfile.js
Last active August 29, 2015 14:15
Build Taist addon (browserify + watchify + gulp)
var gulp = require('gulp')
, fs = require('fs')
, browserify = require('browserify')
, watchify = require('watchify')
, reactify = require('reactify')
, insert = require('gulp-insert')
, source = require('vinyl-source-stream')
;
function handleError(name) {
@wmakeev
wmakeev / google-script.js
Last active November 25, 2015 13:51
JsDoc
/**
* @namespace DriveApp
* @property {function} searchFiles
*/
/**
* @namespace Utilities
* @property {function} formatString
*/
@wmakeev
wmakeev / new_workaroud.js
Created March 12, 2015 08:03
Call constructor without new
var SomeClass = function (options) {
if ( ! (this instanceof SomeClass)) {
return new SomeClass(options);
}
// code
};
(defn group-by [f]
(fn [rf]
(let [groupped-value (volatile! (transient {}))]
(fn
([] (rf))
([result]
(rf (rf result (persistent! @groupped-value))))
([result input]
(let [key (f input)]
(vswap! groupped-value assoc! key (conj (get @groupped-value key []) input))
@wmakeev
wmakeev / map-transformer.js
Last active August 29, 2015 14:17
Transducers (snippets)
var Map = function(f, xf) {
this.f = f;
this.xf = xf;
};
Map.prototype.init = function() {
return this.xf.init();
};
Map.prototype.result = function(result) {
return this.xf.result(result);
};
@wmakeev
wmakeev / async-send-1.js
Last active August 29, 2015 14:19
scaleApp (vision)
var processFile = require('file-processsor');
module.exports = function(sb) {
return {
init: function(options) {
sb.on('new-file', function(ch, file, next) {
processFile(file).then(function (processedFile) {
sb.send('file', processedFile, function (err, result) {
if (err) {
sb.emit('error', err);