loops

How to run every script in a directory except itself?

I have a folder full of *.command files on my OS X workstation. (For those that don't know, *.command files are just shell scripts that launch and run in a dedicated Terminal window). I've dragged this folder onto my Dock to use a "stack" so I can access and launch these scripts conveniently via a couple clicks. I want to add a new ...

how to apply "catch-all" exception clause to complex python web-scraping script?

Hi, I've got a list of 100 websites in CSV format. All of the sites have the same general format, including a large table with 7 columns. I wrote this script to extract the data from the 7th column of each of the websites and then write this data to file. The script below partially works, however: opening the output file (after running ...

Populating an array of hashes with arrays of hashes

I am currently developing a piece of monitoring software that takes an input file of server names and ip addresses and creates a rudimentary database of information. I want to default some values as it processes the config file and it works fine for the first time round the loop but any subsequent entries get created with weird (well wei...

jQuery - Apply style to center div in a three column row?

I'm trying to add borders to the middle column in a three column row. This: var subcount = $j('#sub > div').size(); Gives me 6, and I'm trying to figure out how to apply a style to the divs in the middle? (in this case, div 2 and div 5) <div id="sub"> <div>div 1</div> <div>div 2</div> <div>div3</div> <div>div 4</div> <div>div 5</div...

detecting the start of a loop in a singly linked link list?

Is there any way of finding out the start of a loop in a link list using not more than two pointers? I do not want to visit every node and mark it seen and reporting the first node already been seen.Is there any other way to do this? ...

Onclick refresh in div using Wordpress Loop

I'm sure this is simple, but I'm a noob, so I'm not sure how to achieve this... Basically, I have 3 separate divs with 3 separate WP loops. I want to create a script to assign certain the "next post" & "previous post" links to refresh within the div, while the other links would behave normally. This would be easier with a normal site, bu...

Loop Problem: Assign data to different strings when in a loop

I have a string which consists of different fields. So what I want to do is get the different text and assign each of them into a field. ex: Hello Allan IBM so what I want to do is: put these three words in different strings like string Greeting = "Hello" string Name = "Allan" string Company = "IBM" //all of it happening in a loop. ...

Will this code be evaluated on every iteration?

I have this for-each-loop: for (Component c : container.getComponents()) { // Loop code } Is getComponents called on every iteration? Does it make sense to call getComponents before the look and only work on a cached array? ...

using Linq to generate a collection of things to be removed from another collection

I'm familiar with the problem of modifying a collection while looping over it with a foreach loop (i.e. "System.InvalidOperationException: Collection was modified"). However, it doesn't make sense to me that when I use Linq to create a List of keys to delete from a dictionary, then loop over my new List, I get the same exception. Code ...

How to apply Loop to working Python Selenium Script?

Hi, I'm trying to figure out how to apply a for-loop to this script and I'm having a lot of trouble. I want to iterate through a list of subdomains which are stored in csv format (ie: one column with 20 subdomains) and print the html for each. They all have the same SourceDomain. Thanks! #Python 2.6 from selenium import selenium impo...

Categorizing non-ID categories PHP loop

On my project there're various search results of different content-types. For unimportant reasons, not all content-types carry a unique ID. However, I tried to write this loop that will detect IDless content-types, and will give them a unique ID. Basically, the results look like this: Category ID 3 Category ID 3 Category ID 4 NON-ID C...

Looping a multidimensional array in php

Hi! I have a multidimensional array like this: array(2) { [1]=> array(3) { ["eventID"]=> string(1) "1" ["eventTitle"]=> string(7) "EVENT 1" ["artists"]=> array(3) { [4]=> array(2) { ["name"]=> string(8) "ARTIST 1" ["description"]=> string(13) "artist 1 desc" ...

Php foreach loop, with looping error messages

Hello, I have a foreach loop that is suppose to check to see if a checkbox is checked by an item. If the checkbox is checked I need to see if the file upload part of the script has a value and if so then proceed to check the file type and size of the file the user is trying to upload. Currently if there is only an error with the firs...

Variables in Anonymous Functions -- Can someone explain the following?

I've been trying to assign a function to onclick event of a dynamically created "a" tag in JavaScript. All of the tags are created in a loop as follows: for ( var i = 0; i < 4; i++ ) { var a = document.createElement( "a" ); a.onclick = function( ) { alert( i ) }; document.getElementById( "foo" ).appendChild( a ); } The alerted v...

Double For loops in R

How do you properly write a double for loop in R? For example, in C I would do int i, j; for (i = 1; i < 6; i++) { for (j=i; j <= 3; j++) { printf("%i,%i\n",i,j); } // Do more operations for i > 3... } which would generate the (artificial) sequence: 1,1 1,2 1,3 2,2 2,3 3,3 In R you do not get the same behaviour...

Can you use the lapply() function to alter the value of input?

I was wondering whether it is possible to use the lapply() function to alter the value of the input, similar to: a1<-runif(100) a2<-function(i){ a1[i]<-a1[i-1]*a1[i];a1[i] } a3<-lapply(2:100,a2) I'm looking for something akin to a for() loop, but using the lapply() infrastructure. I haven't been able to get rapply() to do this. The r...

Is LINQ Join operator using Nested Loop, Merge, or HashSet Joins?

Hello Does anyone know what Join algorith does LINQ performs with its Join operator. Is it NestedLoop, Merge, or HashSet? Is there any way to specify a different one, if supported? Regards Albert ...

C: Looping without using looping statements or recursion

I want to write a C function that will print 1 to N one per each line on the stdout where N is a int parameter to the function. The function should not use while, for, do-while loops, goto statement, recursion, and switch statement. Is it possible? I want to find an answer to this as this a challenge question ...

Simple 'for' loop crashing program on final iteration

The below program seems to be crashing at the very end each time, and I'm assuming that this is because once I get to i = (size-1) then wordList[i+1] won't return anything, returns null, or something equivalent. Any way around this? Am I correct that this is the source of my problem? #include <iostream> #include <string> #include <vecto...

escaping the .each { } iteration early in Ruby

code: c = 0 items.each { |i| puts i.to_s # if c > 9 escape the each iteration early - and do not repeat c++ } I want to grab the first 10 items then leave the "each" loop. What do I replace the commented line with? is there a better approach? something more Ruby idiomatic? ...