I really want to learn how to program. A friend suggested I buy vs 2005 or a newer version if I'm serious about it. Is there a cheaper route? I would like to start with c#.
dear experts,
I have a vector t_vec that stores references to instances of class Too. The code is shown below. In the main , I have a vector t_vec_2 which has the same memory address as B::t_vec.
But when I try to access t_vec_2[0].val1 it gives error val1 not declared.
Could you please point out what is wrong? Also, if you know of a better way to return a vector from a method, please let me know! Thanks in advance.
class Too {
public:
Too();
~Too(){};
int val1;
};
Too::Too(){
val1 = 10;
};
class B {
public:
vector<Too*> t_vec;
Too* t1;
vector<Too*>& get_tvec();
B(){t1 = new Too();};
~B(){delete t1;};
};
vector<Too*>& B::get_tvec(){
t_vec.push_back(t1);
return t_vec;
}
int main(){
B b;
b = B();
vector<Too*>& t_vec_2 = b.get_tvec();
// Getting error
std::cout << "\n val1 = " << t_vec_2[0].val1;
return 0;
}
I want to filter some reserved word on my title form.
$adtitle = sanitize($_POST['title']);
$ignore = array('sale','buy','rent');
if(in_array($adtitle, $ignore)) {
$_SESSION['ignore_error'] = '<strong>'.$adtitle.'</strong> cannot be use as your title';
header('Location:/submit/');
exit;
How to make something like this. If
user type Car for sale the sale
will detected as reserved keyword.
Now my current code only detect single keyword only.
Hi all,
I'm using Jquery's toggle event to do some stuff when a user clicks a checkbox, like this:
$('input#myId').toggle(
function(){
//do stuff
},
function(){
//do other stuff
}
);
The problem is that the checkbox isn't being ticked when I click on the checkbox. (All the stuff I've put into the toggle event is working properly.)
I've tried the following:
$('input#myId').attr('checked', 'checked');
and
$(this).attr('checked', 'checked');
and even simply
return true;
But nothing is working. Can anyone tell me where I'm going wrong?
Edit - thanks to all who replied. Dreas' answer very nearly worked for me, except for the part that checked the attribute. This works perfectly (although it's a bit hacky)
$('input#myInput').change(function ()
{
if(!$(this).hasClass("checked"))
{
//do stuff if the checkbox isn't checked
$(this).addClass("checked");
return;
}
//do stuff if the checkbox isn't checked
$(this).removeClass('checked');
});
Thanks again to all who replied.
I want to know why we always use Sorting algorithm like (Insertion Sort or Merge Sort,...) just for lists and arrays? And why we do not use these algorithms for stack or queue?
I'm debugging from the python console and would like to reload a module every time I make a change so I don't have to exit the console and re-enter it. I'm doing:
>>> from project.model.user import *
>>> reload(user)
but I receive:
>>>NameError: name 'user' is not defined
What is the proper way to reload the entire user class? Is there a better way to do this, perhaps auto-updating while debugging?
Thanks.
Hi stackoverflow,
I apologize in advance for the possible stupidity of this question. However, the following has been the source of some confusion for me and I know the people here will be able to handily clear up the confusion for me. Basically, I would like to finally understand the relationship between any and all of the following terms. Some of the terms I do actually understand pretty well, but some of them are similar in my mind and I would like to once and for all to see their relationships/distinctions laid out all at once. They are:
compiler
interpreter
bytecode
machine code
assembler
assembly language
binary
object code
executable
Ideally, an answer would use examples from Java and C++ and other well-known programming languages that a young-ish student like me would be familiar with. Also, if you want to throw in any other useful terms that would be fine too :)
i am reading a csv file and i want to store this in datastore, but i am getting string from file for datetime field.
i want to type cast it to datetime
also same for date and time separately
error::BadValueError: Property HB_Create_Ship_Date must be a datetime
I am trying to run a function from a PHP script in the form action.
My code:
<?php
require_once ( 'username.php' );
echo '
<form name="form1" method="post" action="username()">
<p>
<label>
<input type="text" name="textfield" id="textfield">
</label>
</p>
<p>
<label>
<input type="submit" name="button" id="button" value="Submit">
</label>
</p>
</form>';
?>
I echo the form but I want the function "username" which is called from username.php to be executed. how can I do this in a simliar way to the above?
I am adapting the Coverflow technique to work with a div. The coverflow function (included as a js file in the head section) is here. When I dynamically add a DIV, it doesn't show up in the coverflow. I am wondering if there is a way to add a destroy function to this js file so that whenever a new div add is added, I can call the destroy method and then reinstantiate. Any suggestions on how I should go about doing this?
//output is "01234 00000" but the output should be or what I want it to be is
// "01234 01234" because of the assignment overloaded operator
#include <iostream>
using namespace std;
class IntArray
{
public:
IntArray() : size(10), used(0) { a= new int[10]; }
IntArray(int s) : size(s), used(0) { a= new int[s]; }
int& operator[]( int index );
IntArray& operator =( const IntArray& rightside );
~IntArray() { delete [] a; }
private:
int *a;
int size;
int used;//for array position
};
int main()
{
IntArray copy;
if( 2>1)
{
IntArray arr(5);
for( int k=0; k<5; k++)
arr[k]=k;
copy = arr;
for( int j=0; j<5; j++)
cout<<arr[j];
}
cout<<" ";
for( int j=0; j<5; j++)
cout<<copy[j];
return 0;
}
int& IntArray::operator[]( int index )
{
if( index >= size )
cout<<"ilegal index in IntArray"<<endl;
return a[index];
}
IntArray& IntArray::operator =( const IntArray& rightside )
{
if( size != rightside.size )//also checks if on both side same object
{
delete [] a;
a= new int[rightside.size];
}
size=rightside.size;
used=rightside.used;
for( int i = 0; i < used; i++ )
a[i]=rightside.a[i];
return *this;
}
For example, class Base has two public methods: foo() and bar(). Class Derived is inherited from class Base. In class Derived, I want to make foo() public but bar() private. Is the following code the correct and natural way to do this?
class Base {
public:
void foo();
void bar();
};
class Derived : public Base {
private:
void bar();
};
This question is for learning purposes. Suppose I am writing a simple SQL admin console using CGI and Python. At http://something.com/admin, this admin console should allow me to modify a SQL database (i.e., create and modify tables, and create and modify records) using an ordinary form.
In the least secure case, anybody can access http://something.com/admin and modify the database.
You can password protect http://something.com/admin. But once you start using the admin console, information is still transmitted in plain text.
So then you use HTTPS to secure the transmitted data.
Questions:
To describe to a learner, how would you incrementally add security to the least secure environment in order to make it most secure? How would you modify/augment my three (possibly erroneous) steps above?
What basic tools in Python make your steps possible?
Optional: Now that I understand the process, how do sophisticated libraries and frameworks inherently achieve this level of security?
I'm trying to write a simple decorator to check the authentication of a user, and to redirect to the login page if s/he is not authenticated:
def authenticate(f):
try:
if user['authenticated'] is True:
return f
except:
redirect_to(controller='login', action='index')
class IndexController(BaseController):
@authenticate
def index(self):
return render('/index.mako' )
But this approach doesn't work. When a user is authenticated, everything is fine. But when the user is not authenticated, redirect_to() doesn't work and I am given this error:
HTTPFound: 302 Found Content-Type: text/html; charset=UTF-8 Content-Length: 0 location: /login
Thank for your help!
My code reads:
import Image
def generateThumbnail(self, width, height):
"""
Generates thumbnails for an image
"""
im = Image.open(self._file)
When I call this function, I get an error:
? AttributeError: type object 'Image' has no attribute 'open'
However in the console:
import Image
im = Image.open('test.jpg')
I have no problem.
Any ideas?
Thanks!
Hello everyone,
I have some experience in Scheme and C++ (read: a semester of each) I know the very basics of Python (used it for physics simulations with the Visual Python module).
Can you recommend me some fun and small (i.e. don't take much time) projects on either Python or C++? I have no real preferences, just that it is fun :P
Thanks for your time!
PS: I've tried projecteuler and python challenge. Euler is good, but more about math than coding, and py challenge just didn't work for me.
I have a list of dicts:
list = [{'title': u'Politics', 'id': 1L, 'title_url': u'Politics'},
{'id': 3L, 'title_url': u'Test', 'title': u'Test'}]
I'd like to remove the list item with title = 'Test'
What is the best way to do this given that the order of the key/value pairs change?
Thanks.
Frustrated in finding the .jar -balls like google collections or "package org.apache.commons.io;". Is there some utility to get them fast like the style-"apt-get source app"? "get-java-jar-ball-3rd source apache commons"?
I've noticed many questions on here from new programmers that can be solved using libraries. When a library is suggested, often times they respond "I don't want to use X library" Is it the learning curve? or ? Just curious!
Dear all,
I've a list of float numbers and I would like to delete incrementally
a set of elements in a given range of indexes, sth. like:
for j in range(beginIndex, endIndex+1):
print ("remove [%d] => val: %g" % (j, myList[j]))
del myList[j]
However, since I'm iterating over the same list, the indexes (range)
are not valid any more for the new list.
Does anybody has some suggestions on how to delete the elements
properly?
Best wishes
Hey I'm used to developing in C and I would like to use C++ in a project. Can anyone give me an example of how I would translate this C-style code into C++ code. I know it should compile in a c++ complier but I'm talking using c++ techniques(I.e. classes, RAII)
typedef struct Solution Solution;
struct Solution {
double x[30];
int itt_found;
double value;
};
Solution *NewSolution() {
Solution *S = (Solution *)malloc(sizeof(Solution));
for (int i=0;<=30;i++) {
S-x[i] = 0;
}
S-itt_found = -1;
return S;
}
void FreeSolution(Solution *S) {
if (S != NULL) free(S);
}
int main() {
Solution *S = NewSolution();
S-value = eval(S-x);// evals is another function that returns a double
S-itt_found = 0;
FreeSolution(S);
return EXIT_SUCCESS;
}
Ideally I would like to be able to so something like this in main, but I'm not sure exactly how to create the class, i've read a lot of stuff but incorporating it all together correctly seems a little hard atm.
Solution S(30);//constructor that takes as an argument the size of the double array
S.eval();//a method that would run eval on S.x[] and store result in S.value
cout << S.value << endl;
Ask if you need more info, thanks.