code not working on server but working on localhost - jquery-ui

Here I am using a code for getting pictures of user and his friends from facebook via app the code is working properly in localhost but not in server. Here is the whole functionality which i want:
on a button click get the user info from facebook data
show popup with drop down
display pictures of the user 1st album
display pictures of the frnds on selection
onclick of any image , the selected image should be displayed in next div
All the above functionalities are achieved on localhost and server but the 1st album images are not displayed properly and on click of any image is also not working
// chk for login of user
function Login(y) {
picidgen = y;
FB.login(function (response) {
if (response.authResponse) {
getUserInfo();//get user info
sbsfbdemo();// open popup
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {
scope: 'email,user_photos,user_videos,read_friendlists,friends_photos',
});
}
function getUserInfo() {
FB.api('/me?fields=name,albums,photos,friends', function (response) {
var str = " Select Friends " + "<select name='frndlst2' onchange='frndsalbum()' id='frndlst2'>"
str += "<option value='" + response.id + "'selected ='selected'>" + "me" + "</option>";
for (i = 0; i < response.friends.data.length; i++)
str += "<option value='" + response.friends.data[i].id + "'>" + response.friends.data[i].name + "</option>"
str += "</select>"
str += " Select Album " + "<select name='frndlst1' onchange='getfrndsphotos()' id='frndlst1'>"
for (x = 0; x < response.albums.data.length; x++)
str += "<option value='" + response.albums.data[x].id + "'>" + response.albums.data[x].name + "</option>"
str += "</select>";
document.getElementById("status").innerHTML = str;
picid = response.albums.data[0].id;
var c = response.albums.data[0].count;
FB.api('/' + picid + '/photos?limit=400&offset=0', function (photos) {
if (photos && photos.data && photos.data.length) {
for (var j = 0; j < c; j++) {
var photo = photos.data[j];
// photo.picture contain the link to picture
var image = document.createElement('img');
image.style.border = "1px solid black";
image.style.margin = "10px";
image.style.cursor = "pointer";
image.src = photo.picture; //user photo is displayed in div(named picture)
picsrc["a" + j] = photo.source;
image.className = "a";
image.id = "a" + j;
document.getElementById("picture").appendChild(image);
}
}
$(".a").bind("click", function () {
var photo = $(this).attr("id");
imagecrop = picsrc[photo];
$("#big-pic").find("img").attr("src", picsrc[photo]);// onclick of image it should be displayed in 2nd div(named big-pic)
});
});
});
}
function frndsalbum() {
document.getElementById("frndlst1").options.length = 0;
var f2 = document.getElementById("frndlst2");
ffrr = f2.options[f2.selectedIndex].value;
FB.api('/' + ffrr + '?fields=albums', function (response) {
var f1 = document.getElementById("frndlst1");
for (var i = 0; i < response.albums.data.length; i++) {
var album = response.albums.data[i];
var option = document.createElement('option');
option.text = album.name;
option.value = album.id;
f1.appendChild(option);
}
document.getElementById("picture").innerHTML = "";
var picid = response.albums.data[0].id;
var c = response.albums.data[0].count; //1st album lenth
FB.api('/' + picid + '/photos?limit=400&offset=0', function (photos) {
if (photos && photos.data && photos.data.length) {
for (var j = 0; j < c; j++) {
var photo = photos.data[j];
// photo.picture contain the link to picture
var image = document.createElement('img');
image.style.border = "1px solid black";
image.style.margin = "10px";
image.style.cursor = "pointer";
image.src = photo.picture;
picsrc["a" + j] = photo.source;
image.className = "a";
image.id = "a" + j;
document.getElementById("picture").appendChild(image);
}
}
$(".a").bind("click", function () {
var photo = $(this).attr("id");
imagecrop = picsrc[photo];
$("#big-pic").find("img").attr("src", picsrc[photo]);
});
});
});
}
function getfrndsphotos() {
document.getElementById("picture").innerHTML = "";
var f1 = document.getElementById("frndlst1");
ffr = f1.options[f1.selectedIndex].value;
FB.api('/' + ffr + '/photos?limit=400&offset=0', function (photos) {
if (photos && photos.data && photos.data.length) {
for (var j = 0; j < photos.data.length; j++) {
var photo = photos.data[j];
// photo.picture contain the link to picture
var image = document.createElement('img');
image.style.border = "1px solid black";
image.style.margin = "10px";
image.style.cursor = "pointer";
image.src = photo.picture;
picsrc["a" + j] = photo.source;
image.className = "a";
image.id = "a" + j;
document.getElementById("picture").appendChild(image);
}
}
$(".a").bind("click", function () {
var photo = $(this).attr("id");
imagecrop = picsrc[photo];
$("#big-pic").find("img").attr("src", picsrc[photo]);
});
});
}

Related

Invalid Ticket when closing orders

I'm trying to close all opened orders, they are all MarketOrders not PendingOrders and have SL and TP set to 0 so they shouldn't close themselves (they are still opened in Terminal). I am storing tickets in the array so my loop looks like:
for(int i = 0; i < trades.size(); ++i) OrderClose(tickets[i], lots[i], Bid, Slippage);
yet I'm still receiving "INVALID TICKET" error, can you tell me why?
It doesn't happen always, its like some orders are closed and some throw Invalid Ticket.
I didn't notice this behavior with only 1 order so I'm assuming it occurs only when there are more of them.
Code:
template < typename T >
struct vector {
vector() {}
vector(int arraySize) {
if (arraySize < 0) { arraySize *= -1; }
ArrayResize(m_data, arraySize);
}
vector(vector & rhs) {
if (size() < rhs.size()) { ArrayResize(m_data, rhs.size()); }
for(uint i = 0; i < size(); ++i) { m_data[i] = rhs.m_data[i]; }
}
vector operator=(vector & rhs) {
if (size() < rhs.size()) { ArrayResize(m_data, rhs.size()); }
for(uint i = 0; i < size(); ++i) { m_data[i] = rhs.m_data[i]; }
return this;
}
T operator[](uint index) { return m_data[index]; }
void push_back( T value ) {
ArrayResize(m_data, ArraySize(m_data) + 1);
m_data[ ArraySize(m_data) - 1 ] = value;
}
uint size() { return ArraySize(m_data); }
void resize(uint newSize) { ArrayResize(m_data, newSize); }
void erase() {
ZeroMemory(m_data);
ArrayResize(m_data, 0);
}
void assign(uint index, T value) {
m_data[index] = value;
}
private:
T m_data[];
};
string Buy(double lots) {
string alertString = "";
int __ticket;
if ( (__ticket = OrderSend (Symbol(), OP_BUY, lots, Ask, Slippage, 0, 0, NULL, m_magic)) != -1 )
{
m_buyTicket.push_back( __ticket );
m_buyLots.push_back( lots );
m_buyPrice.push_back( Ask );
m_buyAccel.push_back( lots / Lots );
m_buyPos.push_back( 0 );
alertString = "Buy function call." +
"\nAsk\t= " + (string)Round(Ask) +
"\nBid\t= " + (string)Round(Bid) +
"\nLots\t= " + (string)Round(lots) +
"\nSpread\t= " + (string)m_spread +
"\nID\t= " + (string)CountAll();
}
else {
int _error = GetLastError();
alertString = "Error " + (string)_error + "\n" + TranslateError( _error );
}
return alertString;
}
string CloseAll() {
string alertString = "CloseAll function call.";
// Buy closing
for (uint i = 0; i < m_buyPrice.size(); ++i)
{
if ( OrderClose ( m_buyTicket[i], m_buyLots[i], Bid, Slippage) )
{
alertString += "\nBuy " + (string)(i+1) + " closed with profit " +
(string)Shrink ( (Bid - m_buyPrice[i]) * m_buyAccel[i] );
}
else
{
int _error = GetLastError();
alertString += "\nError " + (string)_error + "\n" + TranslateError( _error ) +
"\n(while closing Buy " + (string)(i+1) + ")";
}
}
// Sell closing
for (uint i = 0; i < m_sellPrice.size(); ++i)
{
if ( OrderClose ( m_sellTicket[i], m_sellLots[i], Ask, Slippage) )
{
alertString += "\nSell " + (string)(i+1) + " closed with profit " +
(string)Shrink ( (m_sellPrice[i] - Ask) * m_sellAccel[i] );
}
else
{
int _error = GetLastError();
alertString += "\nError " + (string)_error + "\n" + TranslateError( _error ) +
"\n(while closing Sell " + (string)(i+1) + ")";
}
}
return alertString;
}
when you close some ticket successfully, you do not remove it from the list trades, right? And it seems you should. Use your struct to clear the elements if order close is successful.
By the way, there's probably no need to reinvent the wheel, use CArrayObj as a container for your elements and delete them once order is closed.

More efficient way to execute this jquery script

Is there a more efficient way to execute the following jquery script? I need to access the 4 individual variables once the script has run, which I will then send to my database using ajax
var column_1 = $('#column-1').sortable("toArray");
for ( var i = 0, n = column_1.length; i < n; i++ ) {
var v = $('#' + column_1[i] ).find('.inner').is(':visible');
column_1[i] = column_1[i] + ":" + v;
}
var column_2 = $('#column-2').sortable("toArray");
for ( var i = 0, n = column_2.length; i < n; i++ ) {
var v = $('#' + column_2[i] ).find('.inner').is(':visible');
column_2[i] = column_2[i] + ":" + v;
}
var column_3 = $('#column-3').sortable("toArray");
for ( var i = 0, n = column_3.length; i < n; i++ ) {
var v = $('#' + column_3[i] ).find('.inner').is(':visible');
column_3[i] = column_3[i] + ":" + v;
}
var column_4 = $('#column-4').sortable("toArray");
for ( var i = 0, n = column_4.length; i < n; i++ ) {
var v = $('#' + column_4[i] ).find('.inner').is(':visible');
column_4[i] = column_4[i] + ":" + v;
}
This code has not been tested. But should work fine, does what you need it to do. ^^
function x ()
{
var columns = new Array();
columns.push({
column_1 : $('#column-1').sortable("toArray"),
column_2 : $('#column-2').sortable("toArray"),
column_3 : $('#column-3').sortable("toArray"),
column_4 : $('#column-4').sortable("toArray")
});
$.each(columns, function (key, item)
{
SaveToDatabase(item);
});
}
function SaveToDatabase (yourArray)
{
$.each(yourArray, function (key, item) {
var v = $('#' + item).find('.inner').is(':visible');
item = item + ":" + v;
});
}

simplify and rearrange my google script for faster process this often stucks in the middle of the process

Can anyone simplify and rearrange my script such that it works faster without stucking . This script was made to extract spreadsheet data from 4 spreadsheets and deleting blank rows based on a column criteria, This script is working well but taking long time and suddenly/often breaks process saying that spreadsheet page needs to refresh thus stopping the entire process. which should follow with rerunning the script. - Thanks in advance.
my script is as follows :
function myFunction() {
// spreadsheets key to extract data.
//Bhaskar 0AjkkHlm3kCphdFh3M2dtRDdoZHhWZlg5UzFjSWZFcVE
//RAmohan 0AjkkHlm3kCphdGFlNTVhSDc5VXVTeS0xc2ZISDRGZlE
//Krishnareddy 0AjkkHlm3kCphdEhDWEllalpoM3VmNE5weUNLZkd4TVE
//Suni 0AjkkHlm3kCphdFUxTXJlN3lGYkRMY2NXUUkzSTVfbEE
var copieddata = SpreadsheetApp.openById('0AjkkHlm3kCphdFh3M2dtRDdoZHhWZlg5UzFjSWZFcVE').
getSheetByName('List').getDataRange().getValues();
//getSheetByName('List').getRange('I6:AT500').getValues();
var s1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
SpreadsheetApp.setActiveSheet(s1);
//getRange(StartingROWS(1,2,3,4,...),StartingCOLUMNS(A,B,C,D..),
s1.getRange(1,1,copieddata.length,copieddata[0].length).setValues(copieddata);
//var col1count = SpreadsheetApp.getActiveSheet().getRange(1,1,copieddata.length,copieddata[0].length).getNumColumns();
//var row1count = SpreadsheetApp.getActiveSheet().getRange(1,1,copieddata.length,copieddata[0].length).getNumRows();
SpreadsheetApp.flush(); //force the data to be written
// here ends sheet 1 -------
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var numRows = sheet.getLastRow();
var datasheet = sheet.getDataRange();
var data = datasheet.getValues();
//Browser.msgBox(" data lenght -" + data.length + " rage is " + datasheet);
for (var i = data.length; i > 0; --i){
var ii=i-1;
var row = data[ii];
var name = row[6];
var len = name.length;
//Browser.msgBox("row number" + i + " ->" + row[10] + "<- its length =" + len);
if(name.length!=3){
//Browser.msgBox("delete ." + i);
sheet.deleteRow(i);
}
SpreadsheetApp.flush(); //force the data to be written
}
SpreadsheetApp.flush(); //force the data to be written
// ------------------
var lrange = SpreadsheetApp.getActiveSheet().getLastRow();
//Browser.msgBox("l range - " + lrange);
var copieddata = SpreadsheetApp.openById('0AjkkHlm3kCphdGFlNTVhSDc5VXVTeS0xc2ZISDRGZlE').
getSheetByName('List').getDataRange().getValues();
var s1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
SpreadsheetApp.setActiveSheet(s1);
s1.getRange((lrange+1),1,copieddata.length,copieddata[0].length).setValues(copieddata);
//var col1count = SpreadsheetApp.getActiveSheet().getRange(1,1,copieddata.length,copieddata[0].length).getNumColumns();
//var row1count = SpreadsheetApp.getActiveSheet().getRange(1,1,copieddata.length,copieddata[0].length).getNumRows();
SpreadsheetApp.flush(); //force the data to be written
// here ends sheet 2 -------
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var numRows = sheet.getLastRow();
var datasheet = sheet.getDataRange();
var data = datasheet.getValues();
//Browser.msgBox(" data lenght -" + data.length + " rage is " + datasheet);
for (var i = data.length; i > 0; --i){
var ii=i-1;
var row = data[ii];
var name = row[6];
var len = name.length;
//Browser.msgBox("row number" + i + " ->" + row[10] + "<- its length =" + len);
if(name.length!=3){
//Browser.msgBox("delete ." + i);
sheet.deleteRow(i);
}
SpreadsheetApp.flush(); //force the data to be written
}
// ------------------
var lrange = SpreadsheetApp.getActiveSheet().getLastRow();
//Browser.msgBox("l range - " + lrange);
var copieddata = SpreadsheetApp.openById('0AjkkHlm3kCphdEhDWEllalpoM3VmNE5weUNLZkd4TVE').
getSheetByName('List').getDataRange().getValues();
var s1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
SpreadsheetApp.setActiveSheet(s1);
s1.getRange((lrange+1),1,copieddata.length,copieddata[0].length).setValues(copieddata);
//var col1count = SpreadsheetApp.getActiveSheet().getRange(1,1,copieddata.length,copieddata[0].length).getNumColumns();
//var row1count = SpreadsheetApp.getActiveSheet().getRange(1,1,copieddata.length,copieddata[0].length).getNumRows();
SpreadsheetApp.flush(); //force the data to be written
// here ends sheet 3 -------
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var numRows = sheet.getLastRow();
var datasheet = sheet.getDataRange();
var data = datasheet.getValues();
//Browser.msgBox(" data lenght -" + data.length + " rage is " + datasheet);
for (var i = data.length; i > 0; --i){
var ii=i-1;
var row = data[ii];
var name = row[6];
var len = name.length;
//Browser.msgBox("row number" + i + " ->" + row[10] + "<- its length =" + len);
if(name.length!=3){
//Browser.msgBox("delete ." + i);
sheet.deleteRow(i);
}
SpreadsheetApp.flush(); //force the data to be written
}
// ------------------
var lrange = SpreadsheetApp.getActiveSheet().getLastRow();
//Browser.msgBox("l range - " + lrange);
var copieddata = SpreadsheetApp.openById('0AjkkHlm3kCphdFUxTXJlN3lGYkRMY2NXUUkzSTVfbEE').
getSheetByName('List').getDataRange().getValues();
var s1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
SpreadsheetApp.setActiveSheet(s1);
s1.getRange((lrange+1),1,copieddata.length,copieddata[0].length).setValues(copieddata);
//var col1count = SpreadsheetApp.getActiveSheet().getRange(1,1,copieddata.length,copieddata[0].length).getNumColumns();
//var row1count = SpreadsheetApp.getActiveSheet().getRange(1,1,copieddata.length,copieddata[0].length).getNumRows();
SpreadsheetApp.flush(); //force the data to be written
// here ends sheet 4 -------
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var numRows = sheet.getLastRow();
var datasheet = sheet.getDataRange();
var data = datasheet.getValues();
//Browser.msgBox(" data lenght -" + data.length + " rage is " + datasheet);
for (var i = data.length; i > 0; --i){
var ii=i-1;
var row = data[ii];
var name = row[6];
var len = name.length;
//Browser.msgBox("row number" + i + " ->" + row[10] + "<- its length =" + len);
if(name.length!=3){
//Browser.msgBox("delete ." + i);
sheet.deleteRow(i);
}
SpreadsheetApp.flush(); //force the data to be written
}
}
spreadsheet link is as follows : Clik here to enter into my spreadsheet
here's my attempt:
function myFunction2() {
var source = ['0AjkkHlm3kCphdFh3M2dtRDdoZHhWZlg5UzFjSWZFcVE',
'0AjkkHlm3kCphdGFlNTVhSDc5VXVTeS0xc2ZISDRGZlE',
'0AjkkHlm3kCphdEhDWEllalpoM3VmNE5weUNLZkd4TVE',
'0AjkkHlm3kCphdFUxTXJlN3lGYkRMY2NXUUkzSTVfbEE'];
var copied = [];
for (var i = 0; i < source.length; i++) {
copied = copied.concat(SpreadsheetApp.openById(source[i]).getSheetByName('List').getDataRange().getValues());
}
for (var j = 0; j < copied.length; j++) {
if (copied[j][6].length != 3) {
copied.splice(j, 1);
j--;
}
}
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
sheet.clearContents();
sheet.getRange(1, 1, copied.length, copied[0].length).setValues(copied);
}
In this I create one big javascript array from the four spreadsheets, remove elements ("rows") from that array (rather than deleting rows in the spreadsheet itself which I presume is the reason why it's slow), clear the destination sheet, and set the values of the modified array in one go.
HTH
Adam

ActionScript Unexpected Slashes, Parenthesis, and Squiggly-brackets?

This ActionScript code I have been working on for a few days now works 100% just fine in JavaScript, but when I try to compile it in ActionScript it says I have unexpected /, ), and } symbols. Is this syntax wrong and if so how should I fix it? I figured I could test it as Javascript for quicker testing using http://jsfiddle.net/ but now I'm like =(
var txt = "This is a [rainbow]test to show that I can[/rainbow] make whatever I want [rainbow]appear as a rainbow[/rainbow] because I am [rainbow]awesome[/rainbow].";
if ((txt.indexOf("[rainbow]") > -1) && (txt.indexOf("[/rainbow]") > -1)) {
var colors = ['f0f', 'f0c', 'f09', 'f06', 'f03', 'f00', 'f30', 'f60', 'f90', 'fc0', 'ff0', 'cf0', '9f0', '6f0', '3f0', '0f0', '0f3', '0f6', '0f9', '0fc', '0ff', '0cf', '09f', '06f', '03f', '00f', '30f', '60f', '90f', 'c0f'];
function rainbowify(text) {
return text.replace(/\[rainbow\](.+?)\[\/rainbow\]/g, function(_, inner) {
return inner.replace(/./g, function(ch, i) {
return '<font color="#' + colors[i % colors.length] + '">' + ch + '</font>';
});
})
}
txt = rainbowify(txt);
document.write(txt);
}​
Well, this is it:
txt = txt.replace("&apos;", "#");
if ((txt.indexOf("[rainbow]") > -1) && (txt.indexOf("[/rainbow]") > -1)) {
var firstChar = txt.indexOf("[rainbow]") + 9;
var lastChar = txt.indexOf("[/rainbow]");
while (lastChar <= txt.lastIndexOf("[/rainbow]")) {
var RAINBOWTEXT = '';
var i = firstChar;
while (i < lastChar) {
RAINBOWTEXT += txt.charAt(i);
i++
}
var text = RAINBOWTEXT;
var texty = '';
colors = new Array('ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000','ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00','99ff00','66ff00','33ff00','00ff00','00ff33','00ff66','00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff','0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff');
i = 0;
while (i <= text.length) {
var t = text.charAt(i);
if (t != undefined) {
texty += "<font color=\"#" + colors[i % colors.length] + "\">" + t + "</font>";
i++;
}
}
texty = texty.replace("> <", "> <");
var REPLACEME = "[rainbow]" + RAINBOWTEXT + "[/rainbow]";
txt = txt.replace(REPLACEME, texty);
if (lastChar == txt.lastIndexOf("[/rainbow]")) {
break;
}
nextChar = lastChar + 10;
firstChar = txt.indexOf("[rainbow]", lastChar) + 9;
lastChar = txt.indexOf("[/rainbow]", lastChar);
}
}
txt = txt.replace("#", "&apos;");

How to create/read/delete cookie in blackberry widget?

How to create/read/delete cookie in blackberry widget?
have same issue but trying out these codes:
function createCookie(name, value, days) {
eraseCookie(name);
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}

Resources