Posts Tagged ‘variables’

How do I clear all variables in the middle of a Python script?

Monday, August 23rd, 2010

I am looking for something similar to ‘clear’ in Matlab: A command/function which removes all variables from the workspace, releasing them from system memory. Is there such a thing in Python?

EDIT: I want to write a script which at some point clears all the variables.

How to restart the command window in Python?

Sunday, August 22nd, 2010

I am looking for something similar to ‘clear’ in Matlab: A command/function which removes all variables from the workspace, releasing them from system memory. Is there such a thing in Python?

Jquery: Turn 3 arrays in to different objects with different IDs

Sunday, August 22nd, 2010

I’ve been fooling around with a very minimalistic jquery admin area menu. The thing is I want jQuery to build 3 equal menus with different ID’s. I managed to do this by creating a function and call it 3 times with different variables, but I’d like to ask my first question on this lovely community:

What is the most minimalistic and efficient way of creating 3 elements with different IDs and content?

d=['Varer','Kate','Produ','Tilbud','Sider','Info','Pref'];

e=['Varer1','Kate1','Produ1','Tilbud1','Sider1','Info1','Pref1'];

f=['Varer2','Kate2','Produ2','Tilbud2','Sider2','Info2','Pref2'];

function menu(){
var e='';
$.each(d,function(a,b){e+='<a href=#'+b+'>'+b+'</a>'});
$('body').append('<div id=c>'+e+'</div>');}
menu();

Thanks in advance

Visual Studio – Change datasource after initial database server is down?

Sunday, August 22nd, 2010

Ok, so I’ve got this Visual Studio 2008 Project I was working with about a year ago perhaps.
And this project had a datagrid that was linked to an external database running on a server off the internet. Now, this databinding was all done using Visual Studio 2008′s built in features. But how can I now change the binding to a different server, without destroying the project? I’ve noticed that a lot of the code that Visual Studio creates makes a mess. So manually trying to change the datasource has allways f*cked up the whole project for me.

I’m not all that good with this stuff, that’s why I used the built in features of Visual Studio. But I noticed that several things appear, like a binding source, and a dataset.
Is it possible to do this? Perhaps even better, making these settings be controlled after the program has been compiled. The way it is now, it’s all hard coded after compiling, and that kinda sucks. I remember trying to do this about a year ago, trying to bind these settings to variables stored in settings. But I never got that to work. Just throwing around ideas here :)

Any help, pointers or whatever is highly appreciated! :)

parsing Textbox.Text with regex query

Sunday, August 22nd, 2010

Hi,

I have the a text box into which I paste the following text:

England has 80 skyscrapers, 2405 houses, 0 spaceships

I want to parse the contents of this textbox and extract the integers to variables eg:

DIM skyscraper as integer

Dim house as integer

dim spaceship as integer

I tried the following regex but It doesn't work:

 Dim skyscraper As New Regex("/([0-9,]+) skyscrapers/")

Any pointers as to what I should be doing? Thanks in advance.

gdb cannot watch variables declared inside for-loop

Sunday, August 22nd, 2010

I am using
gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5_5.1)

and I cannot watch variables declared inside for-loop. I tried to recreate this behavior on a smaller example but it worked fine. Seems like this problem shows up only inside complex class member functions. Please, advise.

EDIT: optimizations are turned off

Need help understanding MVVM Tutorial, RelayCommand & Use of lambdas

Sunday, August 22nd, 2010

i am reading this tutorial

i don’t understand what the below code is trying to do. 1st, the syntax reminds me properties, but with add/remove instead.

but what is CommandManager.RequerySuggested?

It delegates the event subscription to
the CommandManager.RequerySuggested
event. This ensures that the WPF
commanding infrastructure asks all
RelayCommand objects if they can
execute whenever it asks the built-in
commands

public event EventHandler CanExecuteChanged
{
    add { CommandManager.RequerySuggested += value; }
    remove { CommandManager.RequerySuggested -= value; }
}

also, save command is configured with lambdas. 1st, there are 2 param variables. will they conflict? i cannot just do something like RelayCommand(this.Save(), this.CanSave) or is there no such syntax.

_saveCommand = new RelayCommand(param => this.Save(),
                                param => this.CanSave );

Is there a PHP function for swapping the values of two variables?

Sunday, August 22nd, 2010

Say for instance I have …

$var1 = ABC
$var2 = 123

and under certain conditions I want to swap the two around like so…

$var1 = 123
$var2 = ABC

Is there a PHP function for doing this rather than having to create a 3rd variable to hold one of the values then redefining each, like so…

$var3 = $var1
$var1 = $var2
$var2 = $var3

For such a simple task its probably quicker using a 3rd variable anyway and I could always create my own function if I really really wanted to. Just wondered if something like that existed?

xor n sets of variables for use in SAT transformation

Sunday, August 22nd, 2010

Hey you guys,
I am doing a transformation from a customoized set cover problem to a sat, so i can mayhaps use a sat solver for my problem. My problem is, that i have several sets of variables that interact together in a term of the sat problem. something along the lines of x_i v x_j v x_k; y_i v y_j v y_k . However what i cant seem to get right is, that both sets of variables must not have the same occupancy as a combination. e.q. X_i can be equal to x_j, but the whole set must not be equally occupated.
How do i express that so i can use it in a sat-solver?

cheers

export variable to previous scope in PHP

Sunday, August 22nd, 2010

Now, before you jump at how you shouldn’t mix scopes: I realize this. However, this is a case where either scope mixing must occur or major code duplication must occur?nothing around it. And I’d prefer scope mixing.

That said, I’d like this code:

function a() {
    $a = "a";
    $b = "b";
    $c = "c";
}
function b() {
    a();
    echo $a . $b . $c;
}
b(); // Output: abc
echo $a; // Should raise a notice that $a is undefined

to be able to work as commented. I know it’s not possible in most languages?I was able to do it in Ruby, though; and wonder if you can do it with PHP.

The names of variables aren’t known beforehand in the real situation.

Again, it’s code duplication or this?absolutely no way around it.

Also, it’d be okay if a had to be something like a('b') or something.


In reality, the code is this:

static function renderError($what, $vararray) {
    foreach($vararray as $key => $val) { /* this foreach is the code we want to decouple */
        $key = 'e_'.$key;
        $$key = htmlspecialchars($val);
    }
    ob_clean();
    exit(eval('?>'.file_get_contents(ROOT."/templates/$what.php")));
}

With a call like E_Render::renderError('NotFound', array( 'requested_url' => '/notfound', 'misspelling' => '/reallynotfound' ));

Then, in templates/NotFound.php, you’d have something like:

<html>
<body>
<?php echo $e_requested_url; ?> could not be found. Did you mean <?php echo $e_misspelling: ?>?
</body>
</html>

We’d really rather not have our template authors do anything more than that…although $e['requested_url'] could be done if nothing better was available.