Skip to content

Instantly share code, notes, and snippets.

View wmakeev's full-sized avatar
💭
💻

Makeev Vitaliy wmakeev

💭
💻
View GitHub Profile
@wmakeev
wmakeev / pdf.js
Created July 5, 2014 14:01
Here is an example of rendering a pdf
phantom = require('phantom')
phantom.create(function(ph) {
ph.createPage(function(page) {
page.open("http://www.google.com", function(status) {
page.render('google.pdf', function(){
console.log('Page Rendered');
ph.exit();
});
});
});
@wmakeev
wmakeev / dynamic_script.js
Last active August 29, 2015 14:03
Dynamic script load
var client_script = document.createElement('script');
client_script.setAttribute('src','https://rawgit.com/wmakeev/moysklad-client/master/build/browser/moysklad-client.js');
document.head.appendChild(client_script);
@wmakeev
wmakeev / createMenu.js
Created August 5, 2014 17:16
Create GoogleScript menu
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Custom Menu')
.addItem('First item', 'menuItem1')
.addSeparator()
.addSubMenu(ui.createMenu('Sub-menu')
.addItem('Second item', 'menuItem2'))
.addToUi();
}
@wmakeev
wmakeev / initGoogleScript.js
Created August 6, 2014 11:56
Инициализации GoogleScript проекта для moysklad-client
var client = MoyskladClient.createClient();
var _ = MoyskladClient.require('lodash');
var userProperties = PropertiesService.getUserProperties();
client.options.filterLimit = 20;
// Auth
client.setAuth(
userProperties.getProperty('MOYSKLAD_LOGIN'),
userProperties.getProperty('MOYSKLAD_PASSWORD')
@wmakeev
wmakeev / UMD.js
Created August 21, 2014 15:34
Universal Module Definition
(function (root, factory) {
if (typeof exports === 'object') {
// CommonJS
module.exports = factory(require('b'));
} else if (typeof define === 'function' && define.amd) {
// AMD
define(['b'], function (b) {
return (root.returnExportsGlobal = factory(b));
});
} else {
@wmakeev
wmakeev / tasting.js
Created August 23, 2014 23:56
Tasting (Taist addon)
/**
* Tasting
* Date: 24.08.14
* Vitaliy V. Makeev ([email protected])
*/
function init() {
var taistApi;
var loadScript = function (src, cb) {
var APP = APP || {};
APP.EventBus = {};
APP.EventBus.bind = function (ev, callback, context) {
var calls = this._callbacks || (this._callbacks = {});
var list = calls[ev] || (calls[ev] = []);
list.push([callback, context]);
return this;
};
@wmakeev
wmakeev / mediator01.js
Created August 27, 2014 16:42
Mediator
var mediator = (function(){
var subscribe = function(channel, fn){
if (!mediator.channels[channel]) mediator.channels[channel] = [];
mediator.channels[channel].push({ context: this, callback: fn });
return this;
},
publish = function(channel){
if (!mediator.channels[channel]) return false;
var args = Array.prototype.slice.call(arguments, 1);
@wmakeev
wmakeev / auto_npm_setup.js
Created October 22, 2014 10:31
Setup unknown npm package on require
(function(){
var r=require;
require=function (n){
try{
return r(n);
}
catch(e){
r('child_process').exec('npm i ' + n,function (err,body){
try{
@wmakeev
wmakeev / move_file.js
Created November 4, 2014 09:16
Move files in Node.js
var fs = require('fs');
var is = fs.createReadStream('source_file');
var os = fs.createWriteStream('destination_file');
is.pipe(os);
is.on('end',function() {
fs.unlinkSync('source_file');
});