User Profile

Collapse

Profile Sidebar

Collapse
Xx r3negade
Xx r3negade
Last Activity: May 11 '09, 10:42 PM
Joined: Apr 17 '08
Location: Fargo, ND
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Xx r3negade
    started a topic quick regex question

    quick regex question

    Hi, I am very bad with regexes.
    I need a regular expression that will reduce a url like this:

    hxxp://example.com/somefolder/something/whatever

    to its base:

    hxxp://example.com

    The two slashes after the http: complicate things. I know I could just remove the "http://" and add it again later, but as a learning experience, I would like to do this regex in a single line....
    See more | Go to post

  • Xx r3negade
    replied to "Magic method" in python
    If I followed your example, I would have to do this:
    Code:
         def write(self, path, fn):
             for arg in self.args:
                 arg.write('/'.join([path, fn]))
    over and over again for a bunch of different methods.

    Here is basically how I ended up doing this:

    Code:
    class Parent(object):
    	def __init__(self):
    		pass
    		
    	def foo(self, arg1, arg2):
    		print
    ...
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    replied to "Magic method" in python
    Alright, now I've just dug myself into a deeper hole.

    What I'm basically trying to do is this:

    I have a base class, called FileSystem. I then have two derived classes called DiskFileSystem and VirtualFileSyst em. Being derived classes, they have common methods like write(), read(), etc.

    Say I want to write the same contents to the same file in a VirtualFileSyst em object and a DiskFileSystem object. Instead...
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    replied to "Magic method" in python
    Is there any way to get the arguments that were passed, too?

    Something like this:
    Code:
    def __getattr__(name, *args):
        # whatever
    Except that obviously doesn't work...
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    started a topic "Magic method" in python

    "Magic method" in python

    Is there any way to do this in python? Basically, a default action that an object performs when a nonexistent method or member is accessed.

    Edit: Nevermind, I found __getattr__(). Feel free to delete.
    See more | Go to post

  • Xx r3negade
    replied to Cannot pass char * array
    in C
    OK, that works. I don't know what's happening with hoststr, though...the only two times that it's used in the program are the ones shown in the code. Whatever, it works though. Thanks.

    EDIT: On a side note, if I replace the code in dnsLookup() so it looks like this:
    Code:
    char * dnsLookup(char * hoststr, unsigned int proto)
    {
       return "testing";
    }
    everything works fine, without...
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    started a topic Cannot pass char * array
    in C

    Cannot pass char * array

    EDIT: Title is a misnomer, it's not an array it's a pointer

    I have a struct that I use to pass arguments to a function referenced by pthread_create( ). It looks like this:

    Code:
    struct __tryConnect_args
    {
        int sock;
        char * hoststr;
        unsigned int port;
        int proto;
    };
    My problem is with the char * hoststr member of the struct. Take a look at this code:...
    See more | Go to post

  • Xx r3negade
    replied to C socket woes
    in C
    That isn't right. AI_PASSIVE is for use with bind() and listen(), not connect()

    iSeries Information Center



    Edit: My code was correct. My firewall was configured to not accept connections from localhost. I don't know what's up with the irrelevant error messages, but the problem is now fixed. Thanks for the help anyway...
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    started a topic C socket woes
    in C

    C socket woes

    I am having trouble using connect() when entering struct addrinfo members as parameters.

    Code:
    int tcpConnect()
    {
        struct addrinfo hints;
        struct addrinfo *ai = NULL;
        int res;
        int sock1;
        char * ipaddr = "127.0.0.1";
        char * port = "80";
    
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_INET;
    ...
    See more | Go to post

  • Xx r3negade
    started a topic C Protocol-Independent Sockets
    in C

    C Protocol-Independent Sockets

    I am learning the C interface to protocol-independent sockets, and I'm very confused. For example I keep reading in tutorials to not use sockaddr_in and sockaddr_in6 (since these are protocol-dependent structures), but I *need* to use them in order to use getaddrinfo(). So to start out: below is a function for a host name lookup. Is there any practical way to do this without using the nasty switch statements and the protocol-dependent structures?...
    See more | Go to post

  • Xx r3negade
    replied to Using late-binding with STL classes
    in C
    *facepalm*
    thanks :D
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    replied to Using late-binding with STL classes
    in C
    Any help please? Still not quite sure what to do...
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    replied to Using late-binding with STL classes
    in C
    I get this compile error

    error: request for member ‘push_back’ in ‘vecptr’, which is of non-class type ‘std::vector'

    Note that "vector" is the type passed to the function, in a different part of the code.

    Edit: The function call looks like this:
    Code:
    fileToContainer<vector<string> >(argv[1], &ph.puzGrid);
    ph.puzGrid being a vector<string>,...
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    started a topic Using late-binding with STL classes
    in C

    Using late-binding with STL classes

    I have a function, which reads input from a file and appends each line of the file to an STL object. I want to use this function with both lists and vectors. Since both of these objects have the push_back method, I thought I'd make a common function that can be used by both. Is there any practical way to do this?

    Function show below:

    Code:
    template<class container>
    // The second argument here must be
    ...
    See more | Go to post

  • Xx r3negade
    started a topic Alias for STL object
    in C

    Alias for STL object

    I'm designing a program that frequently deals with coordinate pairs. I've decided to use stl::pair for this purpose. As these are all coordinate pairs, they will all be of type pair<int, int>. My question is, rather than declaring pair<int, int> each time, like seen here:
    Code:
    pair<int, int> foo;
    void bar(pair<int, int>* biz) {
    return;
    }
    can I create some kind of alias that...
    See more | Go to post

  • Xx r3negade
    replied to Copy a list
    OK thanks. And about the second part of my question...is there any logical reason for python to do this? Isn't it inconsistent for the assignment operator to assign a value to some data types and a reference to others? Just wondering why they did this.
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    replied to Web Apps in Python... Where Do I Start?
    No, if you don't yet know how to code, Django is a horrible idea. Go through the tutorial, write some demo apps, and make sure that you feel comfortable with the language. Then write some CGI scripts (like a login form, comment box, etc.) so you know how cookies, post data, sessions, etc. work. *Then* take a look at Django.
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    started a topic Copy a list

    Copy a list

    Consider the following code:
    Code:
    listA = [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'], ['i', 'j', 'k', 'l']]
    changeCoordinates = ((2, 3), (1, 3))
    
    for coordinateList in changeCoordinates:
    	listB = listA[:]
    	x = coordinateList[0]
    	y = coordinateList[1]
    	
    	listB[x][y] = 'foo'
    	print "list A: %s" % listA
    	print "list B: %s" % listB
    ...
    See more | Go to post

  • Xx r3negade
    replied to Trouble escaping regex strings
    Ah, I can't believe I didn't catch that, thanks.
    See more | Go to post

    Leave a comment:


  • Xx r3negade
    replied to Trouble escaping regex strings
    Replace a "." with another "."? What???...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...