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?
Reading the changes in Python 3.1, I found something... unexpected:
The sys.version_info tuple is now a named tuple:
I never heard about named tuples before, and I thought elements could either be indexed by numbers (like in tuples and lists) or by keys (like in dicts). I never expected they could be indexed both ways.
Thus, my questions are:
What are named tuples?
How to use them?
Why/when should I use named tuples instead of normal tuples?
Why/when should I use normal tuples instead of named tuples?
Is there any kind of "named list" (a mutable version of the named tuple)?
Say i have these classes
ViewA and ViewB
In objective C using the delegate pattern I could do
@protocol ViewBDelegate{
- (void) doSomething();
}
then in ViewB interface:
id<ViewBDelegate> delegate;
then in ViewA implementation i set the delegate:
viewB.delegate = self;
and now I can call in doSomething from viewB onto any that unknown type delegate.
[delegate doSomething];
"C++ How to Program" has been the worse read an can't find simple examples that demonstrates basic design patterns.
What i'm looking for in C++ is:
events ActionScript and java
either delegates or notifications in Objective C
anything that allows class A, Class B and Class C to know that ClassX
didSomething()!!!
thanks
Hey I'm wondering how i can get this code to work, basically i want to keep the lines of $filename as long as they contain the $user in the path. Sry, perl noob.
open STDERR, ">/dev/null";
$filename=`find -H /home | grep $file`;
@filenames = split(/\n/, $filename);
for $i (@filenames) {
if ($i =~ m/$user/) {
#keep results
} else {
delete $i; # does not work.
}
}
$filename = join ("\n", @filenames);
close STDERR;
I know you can delete like delete $array[index] but I don't have an index with this kind of loop that I know of.
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
A friend of mine is interested in learning how to program computers, but she knows nothing about programming. I suggested that Python might be a good language to start with, but after some googling, I couldn't find any tutorials that covered both programming and Python in an adequate way.
I don't want her to go through the tiresome "learn algorithms in pseudocode first" routine. Instead, I'd like a tutorial that will explain the basic ideas while working towards a real goal, e.g. a very simple console game.
Does anyone know of any such tutorials? Do you think that I'm mistaken in how I'm handling this? Is Python a bad choice? I know that something like C, C++ or Java won't work - too many details will be very counterproductive. On the other hand, I think that Lisp might be too mathematical and abstract. Python, on the other hand, will let her even do something like coding primitive graphical games in a short period of time.
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 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#.
I know charwise positions of matches like 1 3 7 8. I need to know their corresponding line number.
Example: file.txt
Match: X
Mathes: 1 3 7 8.
Want: 1 2 4 4
$ cat file.txt
X2
X
4
56XX
[Added: does not notice many linewise matches, there is probably easier way to do it with stacks]
$ java testt
1
2
4
$ cat testt.java
import java.io.*;
import java.util.*;
public class testt {
public static String data ="X2\nX\n4\n56XX";
public static String[] ar = data.split("\n");
public static void main(String[] args){
HashSet<Integer> hs = new HashSet<Integer>();
Integer numb = 1;
for(String s : ar){
if(s.contains("X")){
hs.add(numb);
numb++;
}else{
numb++;
}
}
for (Integer i : hs){
System.out.println(i);
}
}
}
I'm working through a book on Ruby, and the author used a slightly different form for writing a class initialization definition than he has in previous sections of the book. It looks like this:
class Ticket
attr_accessor :venue, :date
def initialize(venue, date)
self.venue = venue
self.date = date
end
end
In previous sections of the book, it would've been defined like this:
class Ticket
attr_accessor :venue, :date
def initialize(venue, date)
@venue = venue
@date = date
end
end
Is there any functional difference between using the setter method, as in the first example, vs. using the instance variable as in the second? They both seem to work. Even mixing them up works:
class Ticket
attr_accessor :venue, :date
def initialize(venue, date)
@venue = venue
self.date = date
end
end
I am trying to write a .sh file that runs many programs simultaneously
I tried this
prog1
prog2
But that runs prog1 then waits until prog1 ends and then starts prog2...
So how can I run them in parallel?
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.
Which is the best practice in this situation? I would like an un-initialized array of the same type and length as the original.
public static <AnyType extends Comparable<? super AnyType>> void someFunction(AnyType[] someArray) {
AnyType[] anotherArray = (AnyType[]) new Comparable[someArray.length];
...or...
AnyType[] anotherArray = (AnyType[]) new Object[someArray.length];
...some other code...
}
Thanks,
CB
In order to place my models in sub-folders I tried to use the app_label Meta field as described here.
My directory structure looks like this:
project
apps
foo
models
_init_.py
bar_model.py
In bar_model.py I define my Model like this:
from django.db import models
class SomeModel(models.Model):
field = models.TextField()
class Meta:
app_label = "foo"
I can successfully import the model like so:
from apps.foo.models.bar_model import SomeModel
However, running:
./manage.py syncdb
does not create the table for the model. In verbose mode I do see, however, that the app "foo" is properly recognized (it's in INSTALLED_APPS in settings.py). Moving the model to models.py under foo does work.
Is there some specific convention not documented with app_label or with the whole mechanism that prevents this model structure from being recognized by syncdb?
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?
This code works fine to find an available room within certain date, but it does not work to show a room that has been booked and canceled
The "hotel" has 4 rooms and 1 of them has been booked an canceled
So even if I make a cancelation, the select method keeps giving me 3 results. Maybe because the second AND is still running. So basically what I need is
check if the room is booked in the selected dates
if it has been booked, check if its canceled
if it has been canceled, or not booked display it. Otherwise not
SELECT RoomNo, NightCost
FROM room, room_types, booking
WHERE typeid = fk1_typeid
and double_bed=1
and single_bed=0
AND canceled = '1' in
(SELECT canceled
from booking, room_booking
where bookingid = fk2_bookingid)
AND RoomNo not in
(SELECT fk1_RoomNo
FROM room_booking
WHERE '2010-04-02' between Check_in
and Check_Out or
'2010-04-03' between Check_in
and Check_Out) ;
I tried to be as clear as possible, i will be around to give more details if needed
I am need to send a return specific value from a mock object based on a specific key value.
concreate class:
map.put("xpath", "PRICE");
search(map);
Test case:
IOurXMLDocument mock = mock(IOurXMLDocument.class);
when(mock.search(.....need help here).thenReturn("$100.00");
how do I mock this method call for this key value pair?
I have grid named 'GridView1' and displaying columns like this
<asp:GridView ID="GridView1" OnRowCommand="ScheduleGridView_RowCommand"
runat="server" AutoGenerateColumns="False" Height="60px"
Style="text-align: center" Width="869px" EnableViewState="False">
<Columns>
<asp:BoundField HeaderText="Topic" DataField="Topic" />
<asp:BoundField DataField="Moderator" HeaderText="Moderator" />
<asp:BoundField DataField="Expert" HeaderText="Expert" />
<asp:BoundField DataField="StartTime" HeaderText="Start" >
<HeaderStyle Width="175px" />
</asp:BoundField>
<asp:BoundField DataField="EndTime" HeaderText="End" >
<HeaderStyle Width="175px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Join" ShowHeader="False">
<ItemTemplate>
<asp:Button ID="JoinBT" runat="server" CommandArgument="<%# Container.DataItemIndex %>"
CommandName="Join" Text="Join" Width="52px" />
</ItemTemplate>
<HeaderStyle Height="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Here what is my requirement is whenever we right click on each row in gridview ,it should display three option join meeting(if we click it will go to
meeting.aspx),,view details(will go to detail.aspx),,Subscribe(subscribe.aspx) just like when we click right any where we can see view,sortby,refresh
like that..Do we need to implement javascript here
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.