Geo location - JS vs JSON - javascript

I am tryign to obtain the geolocation of the user browsing using maxmind's free service
http://j.maxmind.com/app/geoip.js
jQuery.getScript('http://j.maxmind.com/app/geoip.js', function()
{
var country = geoip_city();
console.log("Your location is: " + country);
});
However, outputting javascript code instead of a json seems like a bit of a problem, since it evals the code from a site outside your control. What would be the best practice to handle such scenarios?

This will show user's city.
<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript">
document.write(geoip_city());
</script>

Related

Using API Key to generate chart for external site but showing login screen

I'm trying to create a burndown chart on a webapp and using the loginkey example code, but switched loginkey to apikey (code below). My API Key is placed where it says CorrectAPIKeyHere, and actual id's for workspace_id and project_id. I have double checked to make sure it's the correct key. Here's what shows up: http://pasteboard.co/P3WXWgPk.png
However, the code works if I'm already logged into Rally. Is there anything I'm missing from my code?
<script type="text/javascript" src="https://rally1.rallydev.com/apps/1.26/sdk.js?apiKey=CorrectAPIKeyHere"></script>
<script type="text/javascript" src="https://rally1.rallydev.com/apps/1.26/sdk.js"></script>
<script type="text/javascript">
function initPage() {
console.log(gon.project_oid);
var rallyDataSource = new rally.sdk.data.RallyDataSource("workspace_id", project_id,"true","false");
console.log($(main_content).width());
var config = {
report: rally.sdk.ui.StandardReport.IterationBurndown,
height: 400,
iterations: iteration_id
};
var report = new rally.sdk.ui.StandardReport(config);
report.display("burndown_chart");
}
rally.addOnLoad(initPage);
</script>
Unfortunately there are a couple different things contributing to your current bad times. API Keys are not supported in App SDK 1.x. They are also not supported by the Analytics1 service which backs that StandardReport component.
So the only way forward is to go back to using LoginKey, which comes with the usual caveats about security, etc. Did you have a working app with LoginKey?
Good news! Api Keys are fully supported now in App SDK 2.1 and the StandardReport component so it should be totally possible to do this now.
Some useful links:
Embedding apps externally:
https://help.rallydev.com/apps/2.1/doc/#!/guide/embedding_apps
The StandardReport component:
https://help.rallydev.com/apps/2.1/doc/#!/api/Rally.ui.report.StandardReport

Saving and restoring current view state of a Tableau graph through javascript API

The problem:
How can I store - and then later retrieve - the custom state of a Tableau view through the javascript-API?
Description:
I am working on a site where we currently allow any user to collaborate a set of Tableau views into a PowerPoint-like online presentation for later use. In our current implementation, the state of the Tableau graphs are not stored, and the user therefore has to apply his or hers desired filter, select worksheets etc. while holding the presentation - every time. This is what we now would like to avoid.
The easiest solution for this would be to store and retrieve one of the "Share"-links accessed through the bottom bar interface; these links contains the state of the current view, but so far, we have not been able to do this: firstly, due to domain issues, we cannot simply fetch the Share-links from the embed-code iframe; and secondly, the API-method workbook.getUrl() does not seem to include the state of the current view.
I am currenty looking into the workbook.rememberCustomViewAsync(name) and workbook.showCustomViewAsync(name) methods, which seem like a possible solution. However, I cannot seem to get any sensible results from either of these two methods, as they both end up giving obscure, non-informative 500 errors when run.
An example file, and the errors:
To better illustrate this issue, I have created a minimal demo (snippet below) that attempts to use the second method described above. When opened in Google Chrome, neither of the two buttons ('save state' and 'retrieve state') work for me, and the following errors can be seen in the Developer Tools (the http response message and developer console output, respectively):
Http response:
<br>
2015-11-11 16:14:17.916
(VkNpWQrCQaIAACQo2YYAAAPi,0,0)
Console error:
POST http://public.tableau.com/vizql/w/Book6_426/v/YRKE/save_customized_view/sessions/208A699D34E14708A2268AA10A827C99-0:0 500 (Internal Server Error)
Does anyone know how I can solve this issue, either by making the provided code example work (the second method described), or through any other means? Any help would be appreciated!
PS: The snippet simulator here will cause a Access-Control-Allow-Origin error. The file has also been published here.
<html>
<head>
<title>A simple Tableau API demo</title>
<!--script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<!--script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau_v8.js"></script-->
<script type="text/javascript" src="https://online.tableau.com/javascripts/api/tableau-2.min.js "></script>
</head>
<body>
<H2>Custom view storage demo</H2>
<button id="remember-button">
Remember state 'test'
</button>
<button id="retrieve-button">
Retrieve state 'test'
</button>
<div id="viz-placeholder" style="width: 1000px; height: 1000px; display: block;"></div>
<script>
// Render tableau graph
function initializeViz() {
var placeholderDiv = document.getElementById("viz-placeholder");
var url = "https://public.tableau.com/views/Book6_426/YRKE";
var options = {
width: placeholderDiv.offsetWidth,
height: placeholderDiv.offsetHeight,
hideTabs: true,
hideToolbar: true,
onFirstInteractive: function() {
workbook = viz.getWorkbook();
activeSheet = workbook.getActiveSheet();
}
};
viz = new tableau.Viz(placeholderDiv, url, options);
}
$(initializeViz)
// Assign and set up button actions for storing and retrieving the custom view
var customViewName = "test";
$('#remember-button').click(function() {
console.log("Remembering: ", customViewName);
// Try to save state, or print error
viz.getWorkbook().rememberCustomViewAsync(customViewName).otherwise(function(err) {
console.log("An error occured:");
console.log(err);
});
});
$('#retrieve-button').click(function() {
console.log("Retrieving: ", customViewName);
// Try to retrieve state, or print error
viz.getWorkbook().showCustomViewAsync(customViewName).otherwise(function(err) {
console.log("An error occured:");
console.log(err);
});
});
</script>
</body>
</html>
Okey, so I have been in contact with Tableau Customer Support, and they seem to have found the issue.
Apparently, certain elements of the javascript-API is only available for Tableau Online and Tableau Server - not Tableau Public.
In other words, the function workbook.rememberCustomViewAsync('customViewName') is not supported for graphs hosted by Tableau Public - such as the one used in the example above (https://public.tableau.com/views/...).

ColdFusion 11 with websockets can't publish a message

I'm trying to get websockets working with ColdFusion. I am unable to send or receive messages and I am at a loss as to why. Am I missing something? Do I need to have any other programs installed? I am using Adobe ColdFusion Builder 3 Developer Edition.
Here is the code I am attempting to use.
Websocket.cfm
<cfwebsocket name="mycfwebsocketobject" onmessage="MessageHandler" subscribeto="stocks" >
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
function MessageHandler(message)
{
alert(message.data);
}
function publishstock()
{
mycfwebsocketobject.Publish('stocks', 'I sent a message!');
}
setInterval('publishstock()',1000);
</script>
Application.cfc
<cfcomponent>
<cfset this.name="Websocket">
<cfset this.wschannels=[{name="stocks"}]>
</cfcomponent>
My goal is to get the MessageHandler function to trigger without explicitly calling it. I have no idea what is wrong and I have matched my code up perfectly with many examples on the web. I have been unsuccessful in both Chrome and Firefox.
I think that the real problem might have something to do with my machine. I found a demo online that worked perfectly, but when I downloaded the source it no longer worked. Is there a way to test for this?
Resources:
https://www.youtube.com/watch?v=Ys6BGrYJhNg
http://www.adobe.com/devnet/coldfusion/articles/html5-websockets-coldfusion-pt1.html
Your setInterval('publishstock()',1000);
Should be:
setInterval(function(){publishstock();},1000);

Search twitter API code-js

I need to use Twitter's Search API. I read twitter's developer documentation and it says that client side authentication is not recommended anymore. But, since mine is really a small application and on a very tight deadline, I decided to use codebird-js.
Here is my code:
<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="codebird.js"></script>
<script type="text/javascript">
function loginTwitter() {
var cb = new Codebird();
cb.setConsumerKey("my_consumer_key","my_consumer_secret");
cb.setToken("my_token", "my_token_secret");
cb.__call(
"search_tweets",
"q=Twitter",
function (reply) {
alert("hey");
},
true
);
}
</script>
Dont think there is any problem with the callback of search tweets, since this is what is documented in codebird-js.Kindly suggest any alternatives to make the code work.
Also, I enabled the option "Allow application to sign in with twitter" in application settings.
You have to make some syntax corrections to your code and to call the "loginTwitter()" function; the code should be:
<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="codebird.js"></script>
<script type="text/javascript">
function loginTwitter() {
var cb = new Codebird();
cb.setConsumerKey("my_consumer_key", "my_consumer_secret");
cb.setToken("my_token", "my_token_secret");
cb.__call(
"search_tweets",
"q=Twitter",
function (reply) {
alert(JSON.stringify(reply)); //do something with the result
},
true
);
};
loginTwitter();
</script>
And don't forget to download the codebird for javascript and put its files into the same folder as your main file (according to the path that you have put in your script).

Ping list of ip addresses using Javascript

I have a list of ip addresses to ping and would like to use Java script to do that.
I tried as the following but there is no output when I clicked the "Test" button.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script>
function myFunction()
{
var myStringArray = [ "10.100.200.133", "10.10.22.0" ];
len=myStringArray.length
for (var i=0; len=myStringArray.length; i<len; i++) {
check=ping(i)
if $check Then
document.write("ip"+ i + "is up")
else
document.write("ip"+ i + "is down")
}
}
</script>
</head>
<body>
<button onclick="myFunction()">Test</button>
</body>
</html>
You can't directly "ping" in JavaScript. There may be a few other ways:
Ajax
Using a Java applet with isReachable
Writing a server-side script which pings, and using AJAX to communicate to your server-side script
You might also be able to ping in Flash (using ActionScript)
There are also some methods for pinging in JavaScript described in this question: Is it possible to ping a server from Javascript?
ping has a very specific meaning: https://www.rfc-editor.org/rfc/rfc1122#section-3.2.2.6, which cannot be replicated using a browser API.
If you want to just test if a web page hosted at a particular IP is available, you can use XMLHttpRequest

Categories

Resources