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;
});
}
Related
Is there any possible way to make a linked list in cypher within one transaction ?
Iv'e tried ForEach with Match but according to neo4jClien it is not possible to set Match in ForEach.
My approach :
public static void save(List<Post> nodes)
{
var gclient = graphdb.getConnection();
var create1 = gclient.Cypher.Create("(p:Post {nodes})");
var match = gclient.Cypher.Match("((t)-[r:lastPost]->(last))");
var create3 = gclient.Cypher.Create("t-[:lastPost]->p, p-[:next]->last");
var delete = gclient.Cypher.Delete("r");
string query = create1.Query.QueryText + " " + match.Query.QueryText + " "
+ create3.Query.QueryText + " " + delete.Query.QueryText;
gclient.Cypher
.Match("(t:Tmp)")
.WithParam("nodes", nodes)
.ForEach("(newPost in {nodes} | " + query + ")")
.ExecuteWithoutResults();
}
Thanks in advance .
this should do the trick.
static Neo4jClient.Cypher.ICypherFluentQuery addnode<T>(Neo4jClient.Cypher.ICypherFluentQuery q, IList<T> items, int idx, string label)
{
string sq = string.Format("({0}:{1} {{{2}}})", "c" + idx, label, "a" + idx);
q = q.Create(sq).WithParam("a" + idx, items[idx]);
return q;
}
static Neo4jClient.Cypher.ICypherFluentQuery addlink<T>(Neo4jClient.Cypher.ICypherFluentQuery q, int idx1, int idx2)
{
string sq = string.Format("{0}-[:LINKEDTO]->{1}", "c" + idx1, "c" + idx2);
q = q.Create(sq);
return q;
}
public static void Sample<T>(List<T> items, GraphClient client)
{
Neo4jClient.Cypher.ICypherFluentQuery q = client.Connection.Cypher;
for (int i = 1; i < items.Count; i++)
{
q = addnode<T>(q, items, i-1, "MYITEM");
if(i>1)
q = addlink<T>(q, i-2, i-1);
}
q.ExecuteWithoutResults();
}
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]);
});
});
}
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
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("'", "#");
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("#", "'");
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);
}