Using gulp + browserify + watchify + coffeeify tries to retranspile javascript instead of coffeescript - coffeescript

When I browserify my coffeescript code the first time it runs fine. However, when I make a change to my source code and watchify tries to re-run the bundling, coffeeify seems to want to run coffeescript against my javascript - based on this error I get from gulp:
events.js:72
throw er; // Unhandled 'error' event
^
SyntaxError: reserved word 'var' while parsing file: /Volumes/dev/app/frontend/editor/main.coffee
This is my Gulpfile:
var gulp = require('gulp');
var gutil = require('gulp-util');
var watchify = require('watchify');
var browserify = require('browserify');
var coffeeify = require('coffeeify');
var source = require('vinyl-source-stream');
var stringify = require('stringify');
var _ = require('underscore');
var browserifyOpts = {
basedir: "./app/frontend/editor",
debug: true,
extensions: ['.coffee'],
entries: ['./main.coffee']
};
var opts = _.extend({}, watchify.args, browserifyOpts);
var bundler = browserify(opts);
var watch = watchify(bundler);
watch.on('update', bundle);
watch.on('log', gutil.log);
function bundle() {
var b = function() {
return bundler
.transform(stringify(['.html']))
.transform('coffeeify')
.bundle()
.pipe(source('main.js'))
.pipe(gulp.dest('app/assets/javascripts/bundles'));
};
return b();
}
gulp.task('default', ['browserify-main']);
gulp.task('browserify-main', bundle);
How can I make the bundling process work with watchify too?

Move your transforms outside of the bundle function:
var bundler = browserify(opts);
bundler.transform(stringify(['.html']))
bundler.transform('coffeeify')
var watch = watchify(bundler);
watch.on('update', bundle);
watch.on('log', gutil.log);
function bundle() {
var b = function() {
return bundler
.bundle()
.pipe(source('main.js'))
.pipe(gulp.dest('app/assets/javascripts/bundles'));
};
return b();
}

Related

How to use for loop one under the last row of the other using google app script?

I need to take data from a basic excel form and paste it on a data table as many times as one of the cells form the form says.
This is the form:
Form
I've tried this:
function COPIARPEGAR() {
var Libro = SpreadsheetApp.getActiveSpreadsheet();
var Form = Libro.getSheetByName("Form")
var CON = Form.getRange('J18').getValue();
var Disciplina = Form.getRange('J20').getValue();
var Masculino = Form.getRange('L22').getValue();
var TituloMasculino = Form.getRange('L20').getValue();
var Femenino = Form.getRange('N22').getValue();
var TituloFemenino = Form.getRange('N20').getValue();
var BBDD = Libro.getSheetByName("BBDD2");
var DisciplinaBBDD = BBDD.getRange('A1:A').getValues()
var UltimaFila = DisciplinaBBDD.filter(String).length
for(var filamasc=UltimaFila+1;filamasc<=Masculino+1;filamasc++) {
BBDD.getRange(filamasc,1).setValue(Disciplina)
BBDD.getRange(filamasc,2).setValue(CON)
BBDD.getRange(filamasc,3).setValue(TituloMasculino)
for(var filafem=UltimaFila+1;filafem<=Femenino+1;filafem++) {
BBDD.getRange(filafem,1).setValue(Disciplina)
BBDD.getRange(filafem,2).setValue(CON)
BBDD.getRange(filafem,3).setValue(TituloFemenino)
}
Logger.log(UltimaFila);
Logger.log(CON);
Logger.log(Disciplina)
}
And as result I always get the smaller number overwrited by the largest number like this:
result
Thanks for yur help!
Your loops are the issue in that you aren't starting at the same rows. Consider running your code in debug mode so you can see your variables value on the right hand part of the screen (such as UltimaFila = 1). I looked at your code, and I think this would work with modifications, but again look at your variables on the right side of your code, and run in debug mode.
function COPIARPEGAR() {
var Libro = SpreadsheetApp.getActiveSpreadsheet();
var Form = Libro.getSheetByName("Form")
var CON = Form.getRange('J18').getValue();
var Disciplina = Form.getRange('J20').getValue();
var Masculino = Form.getRange('L22').getValue();
var TituloMasculino = Form.getRange('L20').getValue();
var Femenino = Form.getRange('N22').getValue();
var TituloFemenino = Form.getRange('N20').getValue();
var BBDD = Libro.getSheetByName("BBDD2");
var DisciplinaBBDD = BBDD.getRange('A1:A').getValues()
var UltimaFila = DisciplinaBBDD.filter(String).length;
//Updated the ending point
for (var filamasc = UltimaFila + 1; filamasc <= Masculino + 1 + UltimaFila; filamasc++) {
BBDD.getRange(filamasc, 1).setValue(Disciplina)
BBDD.getRange(filamasc, 2).setValue(CON)
BBDD.getRange(filamasc, 3).setValue(TituloMasculino)
}
//See the starting points change
var DisciplinaBBDD = BBDD.getRange('A1:A').getValues()
var UltimaFila = DisciplinaBBDD.filter(String).length
//Updated the ending point
for (var filafem = UltimaFila + 1; filafem <= Femenino + 1 + UltimaFila; filafem++) {
BBDD.getRange(filafem, 1).setValue(Disciplina)
BBDD.getRange(filafem, 2).setValue(CON)
BBDD.getRange(filafem, 3).setValue(TituloFemenino)
}
Logger.log(UltimaFila);
Logger.log(CON);
Logger.log(Disciplina)
}
How To Debug Your Code

Haxe sys.net.UdpSocket Error: Custom(std#socket_recv_from)

I'm trying to make UDP connection with sys.net.UdpSocket library in Haxe.
Server: Node JS
Client: Haxe ()
var udpsocket:UdpSocket = new UdpSocket();
var addr:Address = new Address();
addr.host = new Host("127.0.0.1").ip;
addr.port = 36000;
while(true){
try{
var bf:Bytes = Bytes.alloc(2048);
var length:Int = udpsocket.readFrom(bf, 0, bf.length, addr); // Error happens here
var msg:String = bf.getString(0, length);
}
catch (e:Dynamic) {
trace(e);
}
}
At udpsocket.readFrom(..) line,
Program throws: Custom(std#socket_recv_from)
According to andyli # https://github.com/andyli/hxudp/issues/6#issuecomment-117970567 (bottom comment) UdpSocket is not implemented fully for neither neko or cpp targets.

Email Settings APIs Authentication

I would like to use the Email Settings API with Apps Script to manage all users signatures on a Google Site. I have used Documents Data APIs before with 2-legged OAuth and it worked just fine. I am currently stuck on the authentication step for Email Settings API.
Code example:
// Setup OAuthServiceConfig
var oAuthConfig = UrlFetchApp.addOAuthService("signature");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken");
//I left scope empty to gain access to all APIs would this scope work scope=https://apps-apis.google.com/a/feeds/emailsettings/2.0/
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setConsumerKey("domain.com");
oAuthConfig.setConsumerSecret("consumerSecret");
// Setup optional parameters to point request at OAuthConfigService. The "signature"
// value matches the argument to "addOAuthService" above.
var options =
{
"method" : method,
"oAuthServiceName" : "signature",
"oAuthUseToken" : "always"
};
var result = UrlFetchApp.fetch("https://apps-apis.google.com/a/feeds/emailsettings/2.0/"+domainName+"/"+userName+"/signature", options);
Logger.log(result);
I get this error: "Unexpected Error (line 37)" which is
var result = UrlFetchApp.fetch("https://apps-apis.google.com/a/feeds/emailsettings/2.0/"+domainName+"/"+userName+"/signature", options);
Any thoughts on what I am doing wrong?
Scopes are here: http://support.google.com/a/bin/answer.py?hl=en&answer=162105
Hope this will help you. This is an working example which will get the user's HTML signature or Update HTML signature
/*
----------------------------------------------------------------------------------
This function will update the HTML signature of a user.
Input will be jason data
To disable signature, pass an empty string as signature value
sample parameter
ob = {user='hps', signature='<b>Regards</b><br>Waqar'}
To disable signature
ob = {user='hps', signature=''}
----------------------------------------------------------------------------------
*/
function updateSignature(ob) {
//ob = {};
//ob.user = "hps";
//ob.signature = "<b>Regards</b><br>Waqar";
var base = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/';
var xmlRaw = '<?xml version="1.0" encoding="utf-8"?>'+
'<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006">'+
'<apps:property name="signature" value="'+htmlEncode(ob.signature)+'" />'+
'</atom:entry>';
var fetchArgs = googleOAuth_('emailSetting',base);
fetchArgs.method = 'PUT';
fetchArgs.payload = xmlRaw;
fetchArgs.contentType = 'application/atom+xml';
var domain = UserManager.getDomain();
var url = base+domain+'/'+ob.user+'/signature';
var urlFetch = UrlFetchApp.fetch(url, fetchArgs);
var status = urlFetch.getResponseCode();
return status;
}
//-----------------------------------------------------------------------------------------------------------
//This function will retreive Signature settings as json.
/*Sample returned object
{user=hps, signature=<b>Regards</b><br>Waqar}
*/
//-----------------------------------------------------------------------------------------------------------
function retrieveSignature(user) {
var user = 'hps';
var base = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/';
var fetchArgs = googleOAuth_('emailSetting',base);
fetchArgs.method = 'GET';
var domain = UserManager.getDomain();
var url = base+domain+'/'+user+'/signature?alt=json';
var urlFetch = UrlFetchApp.fetch(url, fetchArgs);
var jsonString = urlFetch.getContentText();
var jsonArray = Utilities.jsonParse(jsonString).entry.apps$property;
var ob = {};
ob.user = user;
for(var i in jsonArray){
ob[jsonArray[i].name] = jsonArray[i].value;
}
return ob;
}
//Google oAuthConfig..
function googleOAuth_(name,scope) {
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey("anonymous");
oAuthConfig.setConsumerSecret("anonymous");
return {oAuthServiceName:name, oAuthUseToken:"always"};
}
//This function will escape '<' and '>' characters from a HTML string
function htmlEncode(str){
str = str.replace(/</g,'<');
return str.replace(/>/g,'>')
}

Module exports class Nodes.js

I'm a Nodes.js noob and I'm trying to get my head around module constructs. Thus far I have a module (testMod.js) defined this class construct:
var testModule = {
input : "",
testFunc : function() {
return "You said: " + input;
}
}
exports.test = testModule;
I attempt to call the testFunc() method thusly:
var test = require("testMod");
test.input = "Hello World";
console.log(test.testFunc);
But I get a TypeError:
TypeError: Object #<Object> has no method 'test'
What the frick am I doing wrong?
It's a namespacing issue. Right now:
var test = require("testMod"); // returns module.exports
test.input = "Hello World"; // sets module.exports.input
console.log(test.testFunc); // error, there is no module.exports.testFunc
You could do:
var test = require("testMod"); // returns module.exports
test.test.input = "Hello World"; // sets module.exports.test.input
console.log(test.test.testFunc); // returns function(){ return etc... }
Or, instead of exports.test you could do module.exports = testModule, then:
var test = require("testMod"); // returns module.exports (which is the Object testModule)
test.input = "Hello World"; // sets module.exports.input
console.log(test.testFunc); // returns function(){ return etc... }

Flex 4 Send and load variables to a new window

I want to post some variables to a new window.
The receiving c# will then generate a CSV which will stream as a download.
In flex this used to be achieved using loadVars and specifying _blank as the target.
I currently use the following:
var myRequest:URLRequest = new URLRequest(url);
var myLoader:URLLoader = new URLLoader();
var myVariables:URLVariables = new URLVariables();
myVariables.CurrentActiveUserID = currentUserID
myVariables.ReportRuleListID = SingleChartID
myRequest.method = URLRequestMethod.POST;
myRequest.data = myVariables;
myLoader.load(myRequest);
But it does not seem to support targeting of new windows.
Any ideas.
Please and thank you.
I finally sorted it with:
private function sendAndLoadCSVData():void {
var swfURL:String = this.loaderInfo.url;
swfURL = swfURL.substr(0,swfURL.lastIndexOf("/") + 1);
var tempDom:Array = swfURL.split("/");
var domURL:String = tempDom.slice(0,3).join("/") + "/";
var url:String = swfURL + "../Reporting/ExportChartCSV.aspx"
// var post_variable:LoadVars = new LoadVars();
var myRequest:URLRequest = new URLRequest(url);
var myLoader:URLLoader = new URLLoader();
var myVariables:URLVariables = new URLVariables();
myVariables.CurrentActiveUserID = currentUserID
myVariables.ReportRuleListID = SingleChartID
myRequest.method = URLRequestMethod.POST;
myRequest.data = myVariables;
navigateToURL(myRequest, '_blank')
//myLoader.load(myRequest);
// Alert.show(url);
}