@ wrote... (5 years, 4 months ago)

Don't check a pointer before deleting it, just delete it.

// don't do this
if ( p ) delete p;

// just do this
delete p;

// ie: this doesn't crash or do anything bad
int* p = NULL;
delete p;

// but you probably need something like this
#define NUL_DEL( p ) { delete p; p = NULL; }
NUL_DEL(p)

But seriously, this isn't the dark ages, you really want to be doing this.

std::shared_ptr<int> p;
...
p.reset(); // no need to set to NULL (or rather null_ptr)
Category: tech, Tags: cpp, programming, stl
Comments: 0
@ wrote... (5 years, 4 months ago)

I know next to nothing about Javascript so I'll need somebody who knows about this stuff to weigh in, but this is how I got jquery to load asynchronously and then fire callbacks.

more…

Category: tech, Tags: html, javascript
Comments: 0
@ wrote... (5 years, 4 months ago)

Depending on the hardware involved, you can dramatically speed up an ssh pipe by changing the encryption type, or turning off compression.

more…

Category: tech, Tags: linux, ssh
Comments: 0
@ wrote... (5 years, 5 months ago)

From what I can tell everybody uses net-snmp, and from what I've seen the documentation is atrocious.

more…

Category: tech, Tags: snmp
Comments: 0
@ wrote... (5 years, 5 months ago)

I'm not sure how else to name this entry, it's rather complicated. So what I was finally able to achieve is to pass a boost::bind to a boost::bind with placeholders, with templated callbacks. I'm not gonna lie, this took me awhile to figure out.

The rational for all of this was that I had a parent class called group, and this group had the list of boost::asio::deadline_timer's and the boost::asio::io_service running in a thread. I wanted the ability for child objects to put work in that thread.

more…

Category: tech, Tags: boost, cpp, templates
Comments: 0
@ wrote... (5 years, 5 months ago)

Django works much better if you do things the right way. Here are the steps for future me.

more…

Category: tech, Tags: django
Comments: 0
@ wrote... (5 years, 5 months ago)

Part of my Why is simple hard? series.

Do you even typedef bro?

more…

Category: tech, Tags: cpp, programming, simple
Comments: 0
@ wrote... (5 years, 5 months ago)

Part of my Why is simple hard? series.

Like most people with taste, I despise Hungarian notation. But, at the end of the day it really is only a style issue and easy enough to fix with a search & replace.

more…

Category: tech, Tags: cpp, programming, simple
Comments: 0
@ wrote... (5 years, 5 months ago)
Controlling complexity is the essence of computer programming.
Brian Kernighan

This has been bugging me for years, and it's getting worse. In some type of ironic paradox, it seems like the worst programmers are (in some ways) the best programmers.

more…

Category: tech, Tags: programming, simple
Comments: 0
@ wrote... (5 years, 7 months ago)

Although I doubt I'm forging into unknown territory, here is a nice little way I came up with to iterate around a box or square.

def next_coord( w, h ):
    """
    get the next x,y coordinates around your box
    w,h are the width and height of your box

    note, the strange ranges are to prevent getting the corners twice
    this loop configuration goes around clockwise from top left

    for x,y in next_coord(3,3):
        print "(%d,%d)" % (x,y),
    >>> (0,0) (1,0) (2,0) (2,1) (2,2) (1,2) (0,2) (0,1)
    """
    for x in range(0,w-1):        # top
        yield x,0
    for y in range(0,h-1):        # right
        yield w-1,y
    for x in range(w-1,0,-1):     # bottom
        yield x,h-1
    for y in range(h-1,0,-1):     # left
        yield 0,y
Category: tech, Tags: programming, python
Comments: 0