URLVariables not working in Haxe project - haxe

how are you doing? I hope fine.
So I'm trying to send an urlRequest and I can't pass the parameters by url so I'm trying to use the URLVariable, but no matter what I try my php always get null.
var request:URLRequest = new URLRequest(SITE_DOMAIN + "/check_login.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.login = emailInput.text;
variables.password = senhaInput.text;
variables.gotogame = "BURACO";
Reflect.setField(variables, "login", emailInput.text);
Reflect.setField(variables, "password", senhaInput.text);
Reflect.setField(variables, "gotogame", "BURACO");
request.data = variables;
request.method = URLRequestMethod.POST;
openfl.Lib.getURL(request);
As you guys can see I'm trying to set the variables in two ways but neither of they are working and I kind of don't know what to do anymore, please help.

Ive used this without problems:
var request:Http = new Http(SERVER + "actions/layout-builder?random=" + Math.random());
request.addParameter("action", "retrieve");
request.addParameter("layoutId", layoutId);
request.onError = function(msg) {
showSimplePopup("Problem loading layout:\n\n" + msg);
}
request.onStatus = function(status:Int) {
}
request.onData = function(response) {
response = StringTools.replace(response, "\r\n", "\n");
layoutCode.text = response;
}
request.request(false);

Related

unable to read empty cells reading excel file using js-xlsx

I have an excel file I am reading using js-xlsx. The code is working fine except where the cells are empty. These cells are ignored. How do I get these cells also when creating my JSON object?
I went through some of the question on SO as well as some other forums for the same problem but nothing satisfactory.
Any help would be welcome. My code is:
reader.addEventListener('load', function(){
var data = this.result;
var wb = XLSX.read(data, {type: 'binary', sheetStubs:true});
// console.log(headers);
wb.SheetNames.forEach(function(sheetName){
//pulling out column headers for tablecreation
var headers = get_header_row(wb.Sheets[sheetName]);
createTableInDB(headers);
// Here is your object
var XL_row_object = XLSX.utils.sheet_to_json(wb.Sheets[sheetName]);
//console.log(XL_row_object);
for(var i=0; i<XL_row_object.length; i++){
var json_object = XL_row_object[i];
if(json_object !== null){
var dataobject = {
"tablename": tname,
"dbname": dbname,
"info": json_object,
"uname": uname
}
dataobject = $.toJSON(dataobject);
$.ajax({
type: "POST",
url: "insertIntoTable.php",
async: false,
data:"pInsertData=" + dataobject,
success: function(msg){
console.log(msg);
}
});
//console.log(json_object);
}
}
});
});
reader.readAsBinaryString(document.querySelector('input').files[0]);
The file is uploaded through an input in HTML.
Thanks in Advance
Just pass default value in sheet_to_json method:
var jsonObj = XLS.utils.sheet_to_json(data.Sheets[data.SheetNames[0]], {
header: 0,
defval: ""
});
The library has an option for that. In your code below:
...
// Here is your object
var XL_row_object = XLSX.utils.sheet_to_json(wb.Sheets[sheetName]);
//console.log(XL_row_object);
...
You should provide the following option, to the options argument {defval: null} as follows:
...
// Here is your object
var XL_row_object = XLSX.utils.sheet_to_json(wb.Sheets[sheetName], {defval: null});
//console.log(XL_row_object);
...
Then, it should work.
Solution 1 .Condition "if(h===undefined)continue;" in "xlsx.core.min.js" comment it out.
or do it properly...
Solution 2 . By passing Condition extra param while running this XLSX.utils.sheet_to_json(wb.Sheets[name] , {blankCell : false}). add a condition on line no. 19150 "if(defval === undefined && blankCell) continue;" in file xlsx.js etc..

How to unpack an google.protobuf.Any type in gRPC nodejs client?

My protobuf file is like this:
syntax = "proto3"; import "google/protobuf/any.proto";
service RoomService {
getTestAny (Hotelid) returns (google.protobuf.Any); }
message Hotelid {
string hotelid = 1;
}
message HtlInDate {
Hotelid hotelid = 1;
string date = 2;
}
My java-gRPC-server code is like that:
#Override
public void getTestAny(Roomservice.Hotelid request, StreamObserver<Any> responseObserver) {
Roomservice.Hotelid hotelid = Roomservice.Hotelid.newBuilder()
.setHotelid("This is Hotelid")
.build();
Roomservice.HtlInDate htlDate = Roomservice.HtlInDate.newBuilder()
.setHotelid(hotelid)
.setDate("This is Data")
.build();
responseObserver.onNext(Any.pack(htlDate));
responseObserver.onCompleted();
}
And I make a request from a nodejs-gRPC-client, which code is like that:
function () {
var client = new services.RoomServiceClient('localhost:6565',
grpc.credentials.createInsecure());
var request = new messages.Hotelid();
var hotelid = "ignore";
request.setHotelid(hotelid);
var call = client.getTestAny(request, function (err, response) {
var obj = response.toObject();
console.log(obj);
});
}
The response in nodejs-gRPC-client is a type of Any. And it contains a data array:
array:["type.googleapis.com/HtlInDate", Uint8Array[10,17,10...]]
I try to use response.toObject() to get HtlInDate instance but I just get like this:
obj:{
typeUrl:"type.googleapis.com/HtlInDate",
value:"ChEKD1RoaXMgaXMgSG90ZWxpZBIMVGhpcyBpcyBEYXRh"
}
So how can I unpack the Any type response and get the HtlInDate instance exactly? Thanks a lot if you have any idea about this!
Currently, the google.protobuf.Any type is not supported in Node.js, either in Protobuf.js, which gRPC uses by default, or by google-protobuf, which is the official first party protobuf implementation.
From documentation:
https://developers.google.com/protocol-buffers/docs/reference/javascript-generated#message
// Storing an arbitrary message type in Any.
const status = new proto.foo.ErrorStatus();
const any = new Any();
const binarySerialized = ...;
any.pack(binarySerialized, 'foo.Bar');
console.log(any.getTypeName()); // foo.Bar
// Reading an arbitrary message from Any.
const bar = any.unpack(proto.foo.Bar.deserializeBinary, 'foo.Bar');
Please take a note that for browser support you need to use webpack(probably with babel loader) or browserify
As found in google-protobuf tests Any is bundled with pack and unpack functions.
Your code could be unpacked like this:
function () {
var client = new services.RoomServiceClient('localhost:6565',
grpc.credentials.createInsecure());
var request = new messages.Hotelid();
var hotelid = "ignore";
request.setHotelid(hotelid);
var call = client.getTestAny(request, function (err, response) {
var obj = response.toObject();
console.log('Any content', obj);
var date = response.unpack(messages.HtlInDate.deserializeBinary, response.getTypeName());
console.log('HtlInDate', date.toObject());
});
}
This will deserialize the bytes received in the Any object.
You could also build some Any using pack function for wrapping TypeUrl and Value:
var someAny = new Any();
someAny.pack(date.serializeBinary(), 'HtlInDate')

Exporting a new object in Node.js

How can I pass the variables port,host,database into this function?
//myjs.js
var redisCaller = function(port,host,database){
};
module.exports = new redisCaller();
if I do:
var myjs = require('./myjs');
how do I pass those variables?
seems like the only way to do it is like this:
module.exports = function(port,host,database){
return new redisCaller(port,host,database);
}
Change myjs.js to:
module.exports = redisCaller;
Then you can do:
var myjs = require('./myjs')(port,host,database);
You don't.
The way you've set up that code makes it impossible to pass variables in, unless you tweak the require. Which then makes you potentially have to know about the port/host/database in any file you use it in.
Instead, maybe just use an 'init'.
For example, app.js -
var redisCaller = require('./myjs');
redisCaller.init(port, host, database);
And the myjs..
var redisCaller = function(){
this.init = function (port,host,database) {
this.connection = ...
}
this.getConnection = function () {
if(!this.connection) { throw "Need to run init first"; }
return this.connection;
}
};
module.exports = new redisCaller();
Anywhere you need the connection...
var redisCaller = require('./myjs');
var conn = redisCaller.getConnection();
//or
var redisCaller = require('./myjs').getConnection();
It's a bit more code, but at least it's easy to reuse across files.. assuming that was your intention.

Node request throwing: Error: Invalid URI "www.urlworksinbrowser.com" or options.uri is a required argument

I'm using Node v0.10.11 on Ubuntu 12.04. I can't figure out what I'm missing to make streams of URLs work with the request module.
This program is trying to go to a mailing list site, find the download links for each month, then download the pages for each month.
Mikael's readme says "The first argument can be either an url or an options object. The only required option is URI, all others are optional.
uri || url - fully qualified uri or a parsed url object from url.parse()"
If I call url.parse(www.targeturl.com), I get
Error: options.uri is a required argument
If I don't use url.parse, I get
Error: Invalid URI "www.freelists.org/archive/si-list/06-2013"
(this link works perfectly fine in my browsers)
I've cut the code down to 42 lines. Any advice welcome
var request = require('request'),
url = require('url'),
stream = require('stream'),
cheerio = require('cheerio'), // a reduced jQuery style DOM library
Transform = require('stream').Transform
var DomStripStream = function(target) {
this.target = target;
stream.Transform.call(this,{objectMode: true});
}
DomStripStream.prototype = Object.create(
Transform.prototype, {constructor: {value: DomStripStream}}
)
DomStripStream.prototype.write = function () {
this._transform.apply(this, arguments);
};
DomStripStream.prototype.end = function () {
this._transform.apply(this, arguments);
this.emit("end");
};
DomStripStream.prototype._transform = function(chunk, encoding, callback) {
chunk = chunk ? chunk.toString() : "";
$ = cheerio.load(chunk);
domLinks = $(this.target);
$(domLinks).each(function (i, link) {
currLink = 'www.freelists.org' + $(link).attr('href')
// currLink = url.parse(currLink)
request(currLink, function (error, response, body) {
console.log(error);
})
});
}
var fs = require("fs"),
output = fs.createWriteStream("out.txt"),
mainPage = new DomStripStream('td a')
request('http://www.freelists.org/archive/si-list').
pipe(mainPage).
pipe(output);
add http:// or https:// in the url

How to read image from Application folder in winjs

How to read image from Application folder in winjs
var item = groupedProducts.getAt(indx);
item.img = Windows.Storage.ApplicationData.current.localFolder.path + "\\" + "3766111.jpg";
groupedProducts.setAt(indx, item);
WinJS.UI.processAll();
You need to use the async APIs to access files in ApplicationData in WinJS, such as the getFileAsync function used below (this is a helper function I use in databinding for one of my apps):
function getLocalLargeMapTile(item) {
return new WinJS.Promise(
function (completed, error, progress) {
var filename;
var sourceFolder;
if (item.latlong) {
var latandlong = item.latlong.split(", ");
var lat = latandlong[0];
var lon = latandlong[1];
filename = lat + lon + ".png";
var appData = Windows.Storage.ApplicationData.current;
sourceFolder = appData.localFolder;
sourceFolder.getFileAsync(filename).then(function (file) {
var mapUrl = window.URL.createObjectURL(file, { oneTimeOnly: true });
completed(mapUrl);
},
function (error) {
handleError(error)
});
}
else {
filename = "ms-appx:///images/megaphone_256x256.png";
completed(filename);
}
}
);
}
What I'm doing in the helper function is checking whether my data includes a latitude and longitude, and if so, checking for a file with a matching filename, and since those files are in the Application Data folder, wrapping the file with an objectURL and returning a promise with the objectURL. Otherwise, I simply return an ms-appx url pointing to a static file in the app's images folder. Here's how I call this helper function, from a programmatic template (I don't think you can do this with a declarative template):
var image = document.createElement("img");
image.className = "item-image";
image.src = "ms-appx:///images/megaphone_256x256.png";
result.appendChild(image);
// additional code omitted
var promise = mapTileUtil.getLocalMapTile(currentItem);
promise.done(function (mapTileUrl) {
image.src = mapTileUrl;
});
For more info on templating functions, which provide greater control over the rendered markup than declarative templates, check out:
http://msdn.microsoft.com/en-us/library/windows/apps/jj585523.aspx
and
http://go.microsoft.com/fwlink/p/?linkid=231499
For more information on Windows Store app development in general, register for App Builder.

Resources