variables

Access Shared Preferences from Different Activity (Android)

When you establish a shared preference such as below... public static final String PREFS_HI = "MyPrefsFile"; Can you access it from other activities just like you would normally do? SharedPreferences settings = getSharedPreferences(PREFS_HI, 0); Or is there something unique that you must do to access the preferences? ...

PHP - Search for variable in array()

If I had this code: $result = 1; $square = array( "00" => -1, "0" => 0, "1" => 1, ); And wanted to know whether $result is equal to ANY of the array VALUES of $square (-1, 0 or 1). I´m am guessing there should be a function that compares a variable to all the array´s values and returs TRUE or FALSE accordingly. If there isn´t suc...

Question about classes.

Let's say I have a class in php, and it includes some functions. The class is named "something". When I load the file on another file, I noticed it goes like: include("the_file_with_the_class.php"); $something = new something(true); now I can do OOP, I know, like $something->the_function, but what is that "(true)" in the variable? Th...

Access variable value where the name of variable is stored in a string in R

similar questions have raised for other languages: C, sql, java, etc. But I'm trying to do it in R. I have ret_series <- c(1, 2, 3); x <- "ret_series"; How do I get (1, 2, 3) by calling some function / manipulation on x, without direct mentioning of ret_series? ...

My variable seems to temporarily be losing its value

I am having trouble with the following script: After setting my $pageurl variable it loses its value for the first time I try to call it and then it regains its value the second time I call it. In the beginning IF structure I set the variable $pageurl to the page variable in my querystring. This works fine, but later in the script whe...

No need to define a variable twice

If a variable could be defined in a function, even if no value is assigned, it becomes a local variable so, is testB() better programming? var test = 'SNAP!' function testA(boolean) { if (boolean) var test = 'OK'; else var test = null; alert(test); } function testB(boolean) { if (boolean) var test = 'OK'; alert(test...

Parameter in Python

Let's say there is a parameter n. Can n be any numbers? For example, question like this: Given a non-negative number num, return True if num is within 2 of a multiple of 10. This is what I am thinking: def near_ten(num): n = int #So I assume n can be any integer if abs(num - n*10) <=2: return True Return False Howe...

python serval variables combine into a dict?

All, A class: class foo(): def __init__(self): self.avar1 = 0 self.bvar2 = 1 self.cvar3 = 3 def debug_info(self): print "avar1:" avar1 print "bvar2:" bvar2 print "cvar3:" cvar3 my question, it is too complex to write the debug_info() if I got a lot of self.vars ,then I want to m...

How to convert keycode to character using javascript

How to convert keycode to character using javascript var key_code = 65; result should be character = "a"; ...

How do I declare a variable that contains a subclass of a class which implements an interface?

I want to declare a variable which holds a class which implements a specific interface. Specifically, I'm trying to store a SocketChannel and a DatagramChannel in the same property so I can use them interchangeably. Both of these classes extend SelectableChannel and also implement ByteChannel, and I wish to call methods from both. I d...

Why insert-select to variable table from XML variable so slow?

Hi I'm trying to insert some data from a XML document into a variable table. What blows my mind is that the same select-into (bulk) runs in no time while insert-select takes ages and holds SQL server process accountable for 100% CPU usage while the query executes. I took a look at the execution plan and INDEED there's a difference. The...

How to check if a string can be used as a variable name in PHP?

In PHP one can use variable variables... For example... class obj { } $fieldName = "Surname"; $object = new obj(); $object->Name = "John"; $object->$fieldName = "Doe"; echo "{$object->Name} {$object->Surname}"; // This echoes "John Doe". However, $fieldName string may contain some characters not allowed in variable names. PHP will s...

Accessing a class' instance variable (NSMutable Array) from another class

Hi all - new to Obj C and programming in general - learned a lot from this site and really appreciate everyone's contributions. My scenario is as follows (programming an iPhone game which explains the funny names) In my main gameLoop (which is in my view controller) if a certain condition is met I create an enemy - the cherry bomb if ...

Bash: Verifying numbers inside line closer to "big" log file

What I'm trying to do: Make a bash script that performs some tests on my system, wich than reads some log files, and in the end points me some analyzes. I have, for example, a log file (and although it's not so big sometimes, I want to save proccess when possible) that has in the end something like this: Ran 6 tests with 1 failures and...

definition pointer variable

hi everybody, i can't understand following defining pointer variable. can you help me? double(*)(double *) foo; note : sory, i edit name of variable func to foo. ...

Security Risk? $_REQUEST variables ... $$ on the local stack

I was talking with one of my programmers earlier and he showed me a piece of code he was considering: foreach($_REQUEST as $var=>$val) { $$var = addslashes($val); } He wanted to be able to use $varName instead of having to write $_REQUEST['varName'] I advised him to use the mysql_real_escape_string instead of addSlashes and to no...

How to pass a variable from settings.py to a view?

I'm getting the project path in my Django app in settings.py using: PROJECT_PATH = os.path.realpath(os.path.dirname(__file__)) I would like to use the PROJECT_PATH value in other views, such as for locating the path to files in my static path. How can I make this into an accessible variable? ...

What is the differnce between "const X a" and "X const a" if X is the class

i have a class name X, what is the difference between "const X a" and "X const a" ...

jQuery and PHP session issue

In uploadify I have a problem passing variable into the php script. Here's the code: $(document).ready(function() { var counter = 0; $("#uploadify").uploadify({ 'uploader' : 'scripts/uploadify.swf', 'script' : 'scripts/uploadify.php?upload', 'scriptData' : {'PHPSESSID' : '<? echo sessi...

jQuery: Basics - Variable Scope Issue

I've hunted around for about an hour or so trying to glean whatever I could about variable scope in jscript/jquery and by all accounts, my code should work. Right now I just want to be able to read a global variable from a function. My code isn't working and right now it's very basic. Eventually I will need to manipulate the global va...