How to accept user input in thesaurus api to display synonyms using flash as3 - api

am working on a project to develop a thesaurus app using flash as3. However my app works fine but it only displays the synonym for the word already being put inside the thesaurus API url. However, I want my app to allow any user input through the input text field. Is there a way to do that? Many thanks in advance. I use "Big Huge Thesaurus API" for synonyms. For example in below API URL only synonyms for word "mother" are displayed.
"http://words.bighugelabs.com/api/2/958af28ac9e3b21c650cbdd24a2466e8/mother/"
Here is my full code.
button1.addEventListener(MouseEvent.CLICK, loadScores);
function loadScores(e:MouseEvent):void {
var fileLoader:URLLoader = new URLLoader();
fileLoader.addEventListener(Event.COMPLETE, scoresLoadComplete);
fileLoader.load(new URLRequest("http://words.bighugelabs.com/api/2/958af28ac9e3b21c650cbdd24a2466e8/mother/"));
}
function scoresLoadComplete(evt:Event):void {
try {
var returnVars = evt.target.data;
highscores.htmlText = returnVars;
trace("Data retrieved successfully");
for (var myVars in returnVars) {
trace(myVars + ": " + returnVars[myVars]);
}
trace("***********************");
} catch (err:Error) {
trace("Can't parse loaded file: " + err.message);
}
}

Have an input text box in your application and set its instance name to "userinput" and change the following line in your code.
fileLoader.load(new URLRequest("http://words.bighugelabs.com/api/2/958af28ac9e3b21c650cbdd24a2466e8/mother/"));
to
fileLoader.load(new URLRequest("http://words.bighugelabs.com/api/2/958af28ac9e3b21c650cbdd24a2466e8/"+userinput.text+"/"));

Related

Get HTML Data,HTML Tags from API in React-Native

I'm making mobile app with React-Native and i wanna get data from my API.But my API's datas , databases has html tags (you can see them in images which i shared) and some character codes because there are also Turkish characters.I already was using this API from my web site and there was no problem but when i try to get data to my react native app , it is getting data as a plain text as you see in my images.How can i get this datas without problem
It's called HTML entity. This is the code that works on browser (not on your case)
var decodeEntities = (function() {
// this prevents any overhead from creating the object each time
var element = document.createElement('div');
function decodeHTMLEntities (str) {
if(str && typeof str === 'string') {
// strip script/html tags
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
element.innerHTML = str;
str = element.textContent;
element.textContent = '';
}
return str;
}
return decodeHTMLEntities;
})();
The code are copied from here HTML Entity Decode
But it only works on the browser because the browser are automatically translate the characters for you.
I don't think passing around unserialized data like this is a good idea. You might want to encode data in server side using url encode or something then decode it in the react-native side
Reference
https://www.w3schools.com/charsets/ref_utf_punctuation.asp
Actually i solved it with this : https://github.com/archriss/react-native-render-html
Thanks

writing content of local file to blob using javascript

I am trying to upload an excel file(named test1.xls) present in my computer in c drive at location->C:\test\test1.xls to google site(https://sites.google.com/xyz).To do so, I am using Google script editor and code shown below. The issue is that I am not able to pass the contents of file test1.txt at location C:\test\test1.txt instead of the text ("Here is some data")shown in code line shown below(var blob = Utilities.newBlob("Here is some data", "text/plain", "test1.xls");).Also what needs to be given instead of "text/plain" as it is excel file.Please let me know how to do that with code as I am new to google scripting/api coding,many thanks in advance.
CODE->
function doPost(e) {
var site = SitesApp.getSiteByUrl("https://sites.google.com/xyz"); Logger.log(site.getName());
var page = site.getChildren()[0];
// Create a new blob and attach it. Many useful functions also return
// blobs file uploads, URLFetch
var blob = Utilities.newBlob("Here is some data", "text/plain", "test1.xls");
try {
// Note that the filename must be unique or this call will fail
page.addHostedAttachment(blob);
}
catch(e){
Logger.log('Hosted attachment error msg:' +e.message);
}
}

QML Password encryption

I am developping an application by QML on nokia mobile phone which deal with a server.
I need to send an encrypted password "using DES encryption algorithm " to the server side.
how can I do this?
I have been used http://www.tero.co.uk/des/ as follow :
import "../js/Des.js" as Core
Button {
id:loginBtn
anchors.centerIn: parent
text: "test encryption"
onClicked: {
var doc = new XMLHttpRequest();
doc.onreadystatechange = function() {
if(doc.readyState == XMLHttpRequest.DONE) {
var a = doc.responseText;
print(a);
}
}
var result = Core.des ("My_key","1234");
print(result);
}
}
the result variable valus is : A????r4
can anyone tell me if i used that library wrong or tell me another solution .
Thanks in advance ..
Two solutions:
Do the DES encryption directly in QML using Javascript, a quick google gave this page http://www.tero.co.uk/des/
Or you create a small wrapper in C++ that you call from javascript to do the DES encryption. There are plenty of libraries available, for example http://delta.affinix.com/qca/

Rally Custom App export to Excel

In Rally we have a custom App which displays a table. Is there a way to export this table to Excel?
Rally Add-in for Excel looks good, but it only works for Office 2010 and we are stuck on 2007. But I did find this solution that's simple and it works in Firefox. Added a button to the app, when clicked I pass in the div_id of the table along with a Title.
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})();
var onClicked = function(sender, eventArgs) {
var buttonValue = eventArgs.value;
tableToExcel('mashup_table', 'Reviews Report Table');
};
Currently there is no way to export data from a table in an App.
Have you seen the Rally Add-in for Excel?
Michael,
You can try and use the data URI scheme to make your export work. It is possible to get the data from a AppSdk table and creating a comma delimited string. You could then make one of the special URIs to download the contents as a .csv and open them in excel.
We have been kicking around the idea of making the SDK be able to export it's data to from their components but the lack of constant support for data URIs has been a blocking point.
I don't know what browsers you have to support internally but that may be a nice start for a client side solution.
Here is a solution that works with ExtJs that you may find useful.

How do I get data from a background page to the content script in google chrome extensions

I've been trying to send data from my background page to a content script in my chrome extension. i can't seem to get it to work. I've read a few posts online but they're not really clear and seem quite high level. I've got managed to get the oauth working using the Oauth contacts example on the Chrome samples. The authentication works, i can get the data and display it in an html page by opening a new tab.
I want to send this data to a content script.
i'm having a lot of trouble with this and would really appreciate if someone could outline the explicit steps you need to follow to send data from a bg page to a content script or even better some code. Any takers?
the code for my background page is below (i've excluded the oauth paramaeters and other )
` function onContacts(text, xhr) {
contacts = [];
var data = JSON.parse(text);
var realdata = data.contacts;
for (var i = 0, person; person = realdata.person[i]; i++) {
var contact = {
'name' : person['name'],
'emails' : person['email']
};
contacts.push(contact); //this array "contacts" is read by the
contacts.html page when opened in a new tab
}
chrome.tabs.create({ 'url' : 'contacts.html'}); sending data to new tab
//chrome.tabs.executeScript(null,{file: "contentscript.js"});
may be this may work?
};
function getContacts() {
oauth.authorize(function() {
console.log("on authorize");
setIcon();
var url = "http://mydataurl/";
oauth.sendSignedRequest(url, onContacts);
});
};
chrome.browserAction.onClicked.addListener(getContacts);`
As i'm not quite sure how to get the data into the content script i wont bother posting the multiple versions of my failed content scripts. if I could just get a sample on how to request the "contacts" array from my content script, and how to send the data from the bg page, that would be great!
You have two options getting the data into the content script:
Using Tab API:
http://code.google.com/chrome/extensions/tabs.html#method-executeScript
Using Messaging:
http://code.google.com/chrome/extensions/messaging.html
Using Tab API
I usually use this approach when my extension will just be used once in a while, for example, setting the image as my desktop wallpaper. People don't set a wallpaper every second, or every minute. They usually do it once a week or even day. So I just inject a content script to that page. It is pretty easy to do so, you can either do it by file or code as explained in the documentation:
chrome.tabs.executeScript(tab.id, {file: 'inject_this.js'}, function() {
console.log('Successfully injected script into the page');
});
Using Messaging
If you are constantly need information from your websites, it would be better to use messaging. There are two types of messaging, Long-lived and Single-requests. Your content script (that you define in the manifest) can listen for extension requests:
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == 'ping')
sendResponse({ data: 'pong' });
else
sendResponse({});
});
And your background page could send a message to that content script through messaging. As shown below, it will get the currently selected tab and send a request to that page.
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {method: 'ping'}, function(response) {
console.log(response.data);
});
});
Depends on your extension which method to use. I have used both. For an extension that will be used like every second, every time, I use Messaging (Long-Lived). For an extension that will not be used every time, then you don't need the content script in every single page, you can just use the Tab API executeScript because it will just inject a content script whenever you need to.
Hope that helps! Do a search on Stackoverflow, there are many answers to content scripts and background pages.
To follow on Mohamed's point.
If you want to pass data from the background script to the content script at initialisation, you can generate another simple script that contains only JSON and execute it beforehand.
Is that what you are looking for?
Otherwise, you will need to use the message passing interface
In the background page:
// Subscribe to onVisited event, so that injectSite() is called once at every pageload.
chrome.history.onVisited.addListener(injectSite);
function injectSite(data) {
// get custom configuration for this URL in the background page.
var site_conf = getSiteConfiguration(data.url);
if (site_conf)
{
chrome.tabs.executeScript({ code: 'PARAMS = ' + JSON.stringify(site_conf) + ';' });
chrome.tabs.executeScript({ file: 'site_injection.js' });
}
}
In the content script page (site_injection.js)
// read config directly from background
console.log(PARAM.whatever);
I thought I'd update this answer for current and future readers.
According to the Chrome API, chrome.extension.onRequest is "[d]eprecated since Chrome 33. Please use runtime.onMessage."
See this tutorial from the Chrome API for code examples on the messaging API.
Also, there are similar (newer) SO posts, such as this one, which are more relevant for the time being.