How can I add a new key/value pair to an existing array inside of nested foreach loops and have that pair persist outside the scope of the loops?
<?PHP
include('magpierss/rss_fetch.inc');
/*
one, two, skip a few...
$urls is an associative array with
database indices as keys and
URLs as values
...
Here is my script code:
// ==UserScript==
// @name test
// @description test
// @include http://*
// @copyright Bruno Tyndall
// ==/UserScript==
var main = function() {
var b = document.getElementsByTagName('body')[0];
var t = document.createElement('div');
t.inn...
I'm trying to find out how much time it takes to execute a Python statement, so I looked online and found that the standard library provides a module called timeit that purports to do exactly that:
import timeit
def foo():
# ... contains code I want to time ...
def dotime():
t = timeit.Timer("foo()")
time = t.timeit(1)
...
I'm new to object oriented javascript. I have a set up method that I want to a) check if an element is null and if so wait and call itself again and b) observe the click event of a button.
ErrorBox.prototype.setUpErrorBox = function(btnClientID) {
if (btnClientID == null) {
setTimeout("setUpErrorBox()", 1000)
return...
Ok. here's the scenario:
function DataFeed(){
function PopulateData()
{
$('div#example').load('http://www.example.com', fxnCallBack);
};
function fxnCallBack()
{
PopulateData();
}
this.activator = function() {
PopulateData();
}
};
var example_obj = new DataFeed;
example_obj.activator();
In the above co...
Does VB.NET have any scope nesting operators like {} in C type languages?
Example C++ type code:
int i;
i = 0;
{
int i;
i++;
}
...
If you want to use global functions and variable dynamically you can use:
window[functionName](window[varName]);
Is it possible to do the same thing for variables in the local scope?
This code works correctly but currently uses eval and I'm trying to think of how else to do it.
var test = function(){
//this = window
var a, b...
I'm not sure I understand scope - does an out-of-scope variable (I'm using Ruby) exist in memory somewhere or does it stop existing (I know you can't access it). Would it be inaccurate to say that an out-of-scope variable does not exist any more?
Maybe this is a philosophical question.
...
I have the following Obj C function that works properly:
NSString* myfunc( int x )
{
NSString *myString = @"MYDATA";
return myString;
}
However if I add code to update a UIImage the compile fails with image1 being unknown. image1 is valid: it's set up in the .h, synthesized and that exact line of code works
in a m...
How can I access a shadowed global variable in C? In C++ I can use :: for the global namespace.
...
What is the best practice/coding standard with regard to the "this" scope is AS3? Is there one? I feel it really helps with standardization and my readability, but sometimes it seems like "too much".
For instance, is the use of "this" in the following really necessary (I know it works without "this")?:
private var _item:Object;
privat...
I make extensive use of inheritance, polymorphisim, and encapsulation but i just realised that i didn't know the following behavior about scope of an object vs a variable. The difference is best shown with code:
public class Obj
{
public string sss {get; set;}
public Obj()
{
sss = "0";
}
}
public partial ...
I'm trying to wrap my head around closures (there's a joke in there somewhere) and I ran across this:
(function () { /* do cool stuff */ })();
How does this work? What's the purpose of putting the function in parens? Why the empty parens afterwards?
...
I run in to something that illustrates how I clearly don't get it yet.
Can anyone please explain why the value of "this" changes in the following?
var MyFunc = function(){
alert(this);
var innerFunc = function(){
alert(this);
}
innerFunc();
};
new MyFunc();
...
class MySymbol
TABLE={}
def initialize(str) @str = str end
def to_s() @str end
def ==(other)
self.object_id == other.object_id
end
end
class String
def my_intern
table = MySymbol::TABLE
unless table.has_key?(self)
table[self] = MySymbol.new(self)
end
table[self]
end
end
"foo".my_intern
In the e...
I can't seem to access instance members of the surrounding class from inside an enum, as I could from inside an inner class. Does that mean enums are static? Is there any access to the scope of the surrounding class's instance, or do I have to pass the instance into the enum's method where I need it?
public class Universe {
public f...
I am unsure about the scope of one static inner class of a non-static class.
In the lines below, would the variable DataContextCreator.Instance (part of a Singleton pattern) point to the same PDataContext instance for all Page objects/page requests or would each object have its own instance?
public class Page : System.Web.UI.Page
{
...
I often find it useful to be able to schedule code to be executed upon leaving the current scope. In my previous life in TCL, a friend created a function we called defer.
It enabled code like:
set fp [open "x"]
defer("close $fp");
which was invoked when the current scope exited. The main benefit is that it's always invoked no m...
You may have notice that later versions of gcc is more strict with standards (see this question)
All inherited members of a template class should be called using the full name, ie.
ParentClass<T>::member instead of just member
But still I have a lot of old code that does not respect this. Adding using ParentClass<T>::member for ea...
New to C++. In the following program I'm writing I get this error:
g++ -o Blob blob.cc
blob.cc: In function 'int nonrecursivecountcells(color (*)[7], int, int)':
blob.cc:41: error: 'grid' was not declared in this scope
Here is the code:
#include <iostream>
enum color {BACKGROUND, ABNORMAL, TEMPORARY};
const int ROW_SIZE = 7;
const in...