I am working in flex and I am just setting a variable to false. It doesnt do anything in the program but everything breaks when I put this line of code in:
somevar = false;
Does anyone know why?
I want to run:
python somescript.py somecommand
But, when I run this I need PYTHONPATH to include a certain directory. I can't just add it to my environment variables because the directory I want to add changes based on what project I'm running. Is there a way to alter PYTHONPATH while running a script? Note: I don't even have a PYTHONPATH variable, so I don't need to worry about appending to it vs overriding it during running of this script.
I have a pagination script that displays a list of all pages like so:
prev [1][2][3][4][5][6][7][8][9][10][11][12][13][14] next
But I would like to only show ten of the numbers at a time:
prev [3][4][5][6][7][8][9][10][11][12] next
How can I accomplish this? Here is my code so far:
<?php
/* Set current, prev and next page */
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 2;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
/* Query the db for total results.
You need to edit the sql to fit your needs */
$result = mysql_query("select title from topics");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$pagination = '';
/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '< a hr_ef="?page='.$prev.'">Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '< a hr_ef="index.php?page='.$i.'">'.$i.'</a>';
}
}
/* Print NEXT link if there is one */
if($page < $total_pages)
{
$pagination .= '< a hr_ef="?page='.$next.'"> Next</a>';
}
/* Now we have our pagination links in a variable($pagination) ready to
print to the page. I pu it in a variable because you may want to
show them at the top and bottom of the page */
/* Below is how you query the db for ONLY the results for the current page */
$result=mysql_query("select * from topics LIMIT $from, $max_results ");
while ($i = mysql_fetch_array($result))
{
echo $i['title'].'<br />';
}
echo $pagination;
?>
What's the best way of writing robust code so that a variable can be checked for null and blank.
e.g.
string a;
if((a != null) && (a.Length() > 0))
{
//do some thing with a
}
I installed emacs 23.3.1 in c:/emacs-23.3.
Following the hints in this page, I updated the site-start.el to set HOME environment variable.
(setenv "HOME" "c:/users/USER/emacs")
And I made c:/users/USER/.emacs (like I did in unix/mac) to write the code for using slime, but it doesn't seem to start slime correctly.
Is this a correct way of setting emacs in Windows 7? Where do I put the .emacs file?
Encapsulation is obviously helpful and essential when accessing members from outside the class, but when referring to class variables internally, is it better to call their private members, or use their getters? If your getter simply returns the variable, is there any performance difference?
I am using PHP's function file_get_contents() to fetch contents of a URL and then I process headers through the variable $http_response_header. Now the problem is that some of the URLs need some data to be posted to the URL (for example, login pages). How do I do that?
I realize using stream_context I may be able to do that but I am not entirely clear.
Thanks.
We have server on Python and client + web service on Ruby. That works only if file from URL is less than 800 k. It seems like "socket.puts data" in a client works, but "output = socket.gets" - not. I think problem is in a Python part. For big files tests run "Connection reset by peer". Is it buffer size variable by default somewhere in a Python?
I want to use the foreach container to iterate through a folder matching something like: "Filename_MMYYYY.xls". That's easy enough to do; but I can't seem to find a way to parse the MMYYYY from the filename and add it to a variable (or something) that i can use as a lookup field for my DimDate table. It seems possible with a flat file data source, but not an excel connection. I'm using Visual Studio 2005. Please help!
I have a varchar @a='a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p' , wich have | delimitted values. I want to split this variable in a array or a table.
Do anyone have any idea about this.
Hi all,
Currently we are using method_missing to catch for calls to SEO friendly actions in our controllers rather than creating actions for every conceivable value for a variable. What we want are URLS like this:
/students/BobSmith
and NOT /students/show/342
IS there a cleaner solution than method_missing?
Thank you!
How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string:
$myText = $myVar . '';
like the ToString() method in Java or .NET.
Hello!
I have this class:
class DoSomething
{
private int timesDone;
...
}
Which is the right way to named variable 'timesDone'?
Sometimes I see named as m_timesDone. Is this correct? Where I can find information about naming guidelines?
Thank you!
Hi folks:
I have a problem with the typedef keywords in C language.
In my program, I use the following codes:
typedef int* a[10];
int main(){
int a[10];
}
they work well. But why there are no conflicts between a variable and a type sharing the same name a?
Regards.
Should I store the user's ID, name & email address in a session variable or should I query for the user's user's ID, name & email address everytime i need to use it?
I just had a test on java and we had to give the definition of
1) Static:
2) IOExcepion:
What I said for static was...a static method is used to define a method as a class method. And I got it wrong so I asked my teacher and he said he wants the actually definition of static not a static method, class or variable just static. Can someone tell me the definition of this and for IOException please Thanks.
In my code, is there a shorthand that I can use to assign a variable the value of a object's property ONLY if the object isn't null?
string username = SomeUserObject.Username; // fails if null
I know I can do a check like if(SomeUserObject != null) but I think I saw a shorthand for this kind of test.
I tried:
string username = SomeUserObject ?? "" : SomeUserObject.Username;
But that doesn't work.
I have a class variable called attributes which lists the instance variables I want to update in a database:
attributes = ['id', 'first_name', 'last_name', 'name', 'name_url',
'email', 'password', 'password_salt', 'picture_id']
Each of the class attributes are updated upon instantiation.
I would like to loop through each of the attributes and build a MySQL update query in the form of:
UPDATE members SET id = self._id, first_name = self._first name ...
Thanks.
What happens to state information held by a class's variable after coming back from a low memory situation?
I know that views will get unloaded and then reloaded later but what about some ancillary classes & data held in them that's used by the controller that launched the view?
Sample scenario in question:
@interface MyCustomController: UIViewController
{
ServiceAuthenticator *authenticator;
}
-(id)initWithAuthenticator:(ServiceAuthenticator *)auth;
// the user may press a button that will cause the authenticator
// to post some data to the service.
-(IBAction)doStuffButtonPressed:(id)sender;
@end
@interface ServiceAuthenticator
{
BOOL hasValidCredentials; // YES if user's credentials have been validated
NSString *username;
NSString *password; // password is not stored in plain text
}
-(id)initWithUserCredentials:(NSString *)username password:(NSString *)aPassword;
-(void)postData:(NSString *)data;
@end
The app delegate creates the ServiceAuthenticator class with some user data (read from plist file) and the class logs the user with the remote service.
inside MyAppDelegate's applicationDidFinishLaunching:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
ServiceAuthenticator *auth = [[ServiceAuthenticator alloc] initWithUserCredentials:username password:userPassword];
MyCustomController *controller = [[MyCustomController alloc] initWithNibName:...];
controller.authenticator = auth;
// Configure and show the window
[window addSubview:..];
// make everything visible
[window makeKeyAndVisible];
}
Then whenever the user presses a certain button, 'MyCustomController's doStuffButtonPressed' is invoked.
-(IBAction)doStuffButtonPressed:(id)sender
{
[authenticator postData:someDataFromSender];
}
The authenticator in-turn checks to if the user is logged in (BOOL variable indicates login state) and if so, exchanges data with the remote service. The ServiceAuthenticator is the kind of class that validates the user's credentials only once and all subsequent calls to the object will be to postData.
Once a low memory scenario occurs and the associated nib & MyCustomController will get unloaded -- when it's reloaded, what's the process for resetting up the 'ServiceAuthenticator' class & its former state?
I'm periodically persisting all of the data in my actual model classes. Should I consider also persisting the state data in these utility style classes? Is that the pattern to follow?
ie, if the factor variable is Climate, with 4 possible values: Tropical, Arid, Temperate, Snow, and a node in my rpart tree is labeled as "Climate:ab", what is the split?
Can i change the format of the output result which is returned when i call the variable name in FSI windows?
I overrided the ToString() funcion in my object, but it does not affect the output results in FSI.
I have a SQL table (MYSQL 4.0 to be precise) composed of the following :
int no (primary)
int field1
int field2
I would like to swap the values of field1 with the values of field2 and vice-versa.
Ex.: 1;2.5;3.76 becomes 1;3.76;2.5
I need a swapping temporary variable of some sort. But I don't think I can use something like
Set @var1 = field1
inside my update statement. And I don't think altering the table to add a temporary column is my best best either.
My classifieds website uses mainly PHP and MySql.
On error, (for example if a variable isn't found), I would like to have an error-page to show, is this possible? And I mean for every error to point to the same error-page.
I am thinking about htaccess, but maybe there are other ways also?
Same with MySql, how is it done there?
Thanks