I need my program to create and edit a config file, which would contain information about set of objects, and than read it at every execution. Is there some sort of guideline for config style that i can use?
Very simple question, hopefully. So, in Python you can split up strings using indices as follows:
>>> a="abcdefg"
>>> print a[2:4]
cd
but how do you do this if the indices are based on variables? E.g.
>>> j=2
>>> h=4
>>> print a[j,h]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: string indices must be integers
I'm new to Python, so this is probably a simple scoping question. The following code in a Python file (module) is confusing me slightly:
if __name__ == '__main__':
x = 1
print x
In other languages I've worked in, this code would throw an exception, as the x variable is local to the if statement and should not exist outside of it. But this code executes, and prints 1. Can anyone explain this behavior? Are all variables declared in a module global/available to the entire module?
Normally is use
$(document).ready(function() {
// do something
});
to do something after dom is loaded.
in the last time i often see
$(function() {
// do something
});
that also works. whats the difference?
I have extracted some data from the file and want to write it in the file 2 but the program says 'sequence item 1: expected string, list found', I want to know how I can convert buffer[] i.e. string into sequence, so that it could be saved in file 2.
file = open('/ddfs/user/data/k/ktrip_01/hmm.txt','r')
file2 = open('/ddfs/user/data/k/ktrip_01/hmm_write.txt','w')
buffer = []
rec = file.readlines()
for line in rec :
field = line.split()
print '>',field[0]
term = field[0]
buffer.append(term)
print field[1], field[2], field[6], field[12]
term1 = field [1]
buffer.append(term1)
term2 = field[2]
buffer.append[term2]
term3 = field[6]
buffer.append[term3]
term4 = field[12]
buffer.append[term4]
file2.write(buffer)
file.close()
file2.close()
Hi all.
Got some trouble with my preg_match.
The code.
$text = 'tel: 012 213 123. mobil: 0303 11234';
$regex_string = '/(tel|Tel|TEL)[\s|:]+(.+)[\.|\n]/';
preg_match($regex_string , $text, $match);
And I get this result in $match[2]
"012 213 123. mobil: 023 123 123"
First question.
I want the regex to stop at the .(dot) but it doesent.
Can someone explain to why it isnt?
Second question.
preg_match uses () to get their match.
Is it possible to skip the parentheses surrounding the different "Tel" and still get the same functionality?
Thnx all stackoverflow is great :D
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?
I would like the SO community let me know what does juniors and proficient .NET Developers should know regarding the following subjects, also some code examples or brainteasers like the ones here will help a lot.
System Types
Collection and Generics
Configuration and Installation
Monitoring and Debugging
File I/O
Globalization
My university has recently limited our access to internet to a very low level,20 MB for a week!!!
and they control our access to internet with "internet lock" software.
How can I double cross these passwords?
I'll appreciate any help with this unfair limitation we've been forced to!!
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.
It traverses to bottom dirs for some unknown reason:
Errorsome
/bin/sh: .??*: not found
make[23]: Entering directory `/m/user/files/dir'
make clean
Makefile
all:
make clean
#The wildcard is the bug. I want to make all hidden files in the current makefile.
#It should match .<some char><some char><any char arbitrary times>
make $$(.??*)
#I want to replace below-like-tihngs with a wildcard above
# make .lambda
# make .lambda_t
clean:
-rm .??*
.lambda:
#do something
.lambda_t:
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
I've made a page that uses jQuery to allow you to place <div>s on the page based on your mouse coordinates when you click.
The page
And here's the javascript:
$('document').ready(function() {
$("#canvas").click(function(e){
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
$(document.createElement('div')).css({'left':x + 'px', 'top':y + 'px'}).addClass('tile').appendTo('#canvas');
});
});
I've found that if you mousedown in the div#canvas and mouseup with your pointer over a placed <div> (or vice versa) then a new <div> doesn't get placed. Why is this?
I'm new at php and mysql stuff and i'm trying to use an avg function but i don't know how to.
I'm trying to do something like this:
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die ("Did not connect to $database");
mysql_query("AVG(column1) FROM table1 ") or die(mysql_error());
mysql_close();
echo AVG(column1);
(Q1)I'd like to see the value printed in the screen, but i'm getting nothing but an error message. How could I print this average on the screen ?
(Q2)If I had a column month in my table1, how could I print the averages by the months ?
Sorry for any bad English, and thanks for the attention.
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.
Hello,
I'm relatively new to C, and this is baffling me right now. It's part of a much larger program, but I've written this little program to depict the problem I'm having.
#include <stdio.h>
int main()
{
signed int tcodes[3][1];
tcodes[0][0] = 0;
tcodes[0][1] = 1000;
tcodes[1][0] = 1000;
tcodes[1][1] = 0;
tcodes[2][0] = 0;
tcodes[2][1] = 1000;
tcodes[3][0] = 1000;
tcodes[3][1] = 0;
int x, y, c;
for(c = 0; c <= 3; c++)
{
printf("%d %d %d\r\n", c, tcodes[c][0], tcodes[c][1]);
x = 20;
y = 30;
}
}
I'd expect this program to output:
0 0 1000
1 1000 0
2 0 1000
3 1000 0
But instead, I get:
0 0 1000
1 1000 0
2 0 20
3 20 30
It does this for any number assigned to x and y. For some reason x and y are overriding parts of the array in memory.
Can someone explain what's going on?
Thanks!
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
This is probably a stupid question, but I can't seem to do it. I want to set up some enums in one class like this:
public enum Direction { north, east, south, west };
Then have that enum type accessible to all classes so that some other class could for instance have:
Direction dir = north;
and be able to pass the enum type between classes:
public void changeDirection(Direction direction) {
dir = direction;
}
I thought that setting the enum to public would make this automatically possible, but it doesn't seem to be visible outside of the class I declared the enum in.
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.
Hi all,
I'd like to use a JS regex to take a string such as the following:
'http://www.somedomain.com/some_directory/some_other_directory/some_image.jpg'
And turn it into this:
'http://www.some_other_domain.com/another_directory/yet_another_directory/size1_some_image.jpg'
Any hints? Additionally, any pointers for books or other resources that give a gentle introduction to mastering regexes in JS and other languages?
Hello,
I would like to sanitize a string in to a URL so this is what I basically need.
Everything must be removed except alphanumeric characters and spaces and dashed.
Spaces should be converter into dashes.
Eg.
This, is the URL!
must return
this-is-the-url
Thanks