FAQ Database Discussion Community


Clearing multiple timeouts properly

javascript,settimeout,multiple-instances,scoping,cleartimeout
I've been struggling for the past day trying to solve this one. I'm trying to get some funky text effects going, basically a glorified string creation. It writes a line a bit like a billboard and to do it I've used setTimeout. Thing is I would like to put it...

Global scope inside if/else for a running median

python,variables,if-statement,global,scoping
I'm implementing a running median algorithm in Python using two heaps. However, the heaps don't grow in size even if I push to them... I suspect it's something to do with the scoping inside if/else statements. I don't really understand how to fix this. import os import numpy import functools...

Is it bad practice to create Divs just to have multiple controllers?

html,angularjs,angularjs-scope,asp.net-web-api2,scoping
Is a bad practice to be creating divs in your HTML just to be able to have multiple controllers? Since you cannot have them in one also the approach of having multiple directives with separate controllers seems like a hack, but correct me if I am wrong. So I have...

Trouble getting function to return TRUE

r,function,for-loop,scoping,logical
I have some code to check to see if the input to a function is a valid US state. I have a CSV file with a State column and those are the only states I care about. So I made this code with a for loop to check if the...

Scoping rules for struct variables in GCC

c,gcc,struct,clang,scoping
Consider the following C program #include <stdio.h> typedef struct s { int x; } s_t; int main() { int x; s_t a; scanf("%d", &x); if (x > 0) { s_t a; a.x = x; } printf("%d\n", a.x); } The a struct variable in the if branch clearly shadows the a...

Google map JS code - “this.activeInfoWindow.close()” - scope & this

javascript,google-maps,google-maps-api-3,scoping
In the following Google map JS code the "this.activeInfoWindow.close()" statement does not work as expected. I think I am missing some important scoping principle here. Is there a better way to do this? I am trying to learn better namespacing and scoping and OO techniques. var data = { "cities":...

C - extern, static, include

c,static,extern,scoping
Scoping in C is confusing as hell. I have a variable: "int qwe". This var should be visible in one or more files - f1.c in this case, but not the another f2.c . Say i have: main.c, f1.c, f2.c, header.h main: call f1(); call f2(); header: #ifndef HEADER_INCLUDED #define...

Rcpp scoping of free variables

r,rcpp,scoping
Say that I have a C++ function dosomething(z) that has a single input variable z, but also a "free" variable located within it (say y). I want to be able to design the scoping so that when I run the Rcpp function, it finds the free variable within the R...

update function in R and variables access

r,scoping
I need to update a model formula inside a function. This is an example: A <- runif(n = 200) # generate some data B <- runif(n = 200) P <- 1/(1+exp(.5-A)) # generate event probability outcome <- runif(n = 200) < P # generate outcome my.function <- function(model, data.to.add) {...

Python: Binomial distribution doesn't work when set as a variable

python,variables,environment-variables,scoping,binomial-theorem
I'm trying to recreate a single player version of a dice game called Dudo. The most relevant information is that six players have six hidden dice, and the point of the game is to guess how many of a certain kind of die are on the table in total (e.g....