Cycling

Matts on 2003-11-12T20:59:49

The Cycling is going well. It's enjoyable (for the most part), and I'm not sick of it yet (it's only about 5.5 miles a day).

The biggest downside is the sweat. There's no real way to combat this (and no shower at work) except to simply shower every day and hope I don't stink too much. Nobody has complained about me yet so touch wood I'm not doing too bad.

The second downside is my car. I love my car (I'm a bit of a motor-head at heart). I love to drive it, and push my driving skills. And it's a fun car to do that in (a Honda Civic Type-R). But owning it is now completely pointless! It's just a big expensive toy. So this weekend I'm going to try and up-sell it for something cheaper. Probably a cheaper Civic or Accord. I'd like something comfortable so that when I am driving I feel relaxed. We'll see what I end up with.

In perl news I've hurt my brain this week with over stretching. I've been working on some code to combine multiple DNS lists into one, using a bitmasked IP address as the result (so I can know which lists an IP was in when I get the result back without having to use multiple A records). This was quite hard as I had to deal with the case of when I got a CIDR within a CIDR - you have to then delete and split the larger CIDR, and recurse.

The problems with this code (aside from the brainwork it took to work out the splitting algorithm) was that I got some very strange results with my bitwise & operations. I would bitwise combine 2 and 8 and get ":". Yes, I was confused too. I haven't tried to replicate this outside of my code, but I think it was doing a stringwise bitwise &. Or something like that. The fix was to make sure I put "int()" around everything I was combining. Ugh.

Oh, and before I forget: rpm-- # sucks.


Cycling

Dom2 on 2003-11-12T21:18:49

Well done -- I'm sure it seems hard at first, but you'll get used to it very quickly. I've been cycling in to work since the beginning of this year[1], and I've lost quite a bit of flab. I feel much fitter for it as well.

However, I'm lucky in that all the way to work is downhill and all the from work is uphill. So I can come home and get straight in the shower.

I love my Brompton. :-)

-Dom

[1] Actually, I cycled in before, it's just that it was such a short distance it was hardly worth mentioning. :-)

Re:Cycling

Matts on 2003-11-12T21:28:09

I assume you need a bike like that because you have nowhere to attach it to outside at work?

Does it ride well? It looks like it would be hard(er) work than it should be...

Re:Cycling

Dom2 on 2003-11-13T18:05:43

Spot on. Well there are some few places to attach it to, but it's a lot less likely to be nicked when under my desk.

As to riding it, it's not terribly hard work. I've got a 5 speed model which is nicely geared. It's easy in the lower gears, but you can notch up a reasonable speed in the high gears. The main difficultly that I found when I started riding was that you're quite high up in the saddle, with smallish handle bars. This makes the bike feel very responsive to your movements. But I'm so used to it now that the last time I used a full size bike, I wondered why the handle bars had to be moved so far to turn the thing...

I'd definitely reccomend them as a commuter bike. The main trouble is that they're a bit expensive... But if you go past a shop that's selling them, try asking if you can take one for a spin.

I think that there are a couple of other people around here with them. I was recommended one by fanf...

-Dom

CIDR addresses

runrig on 2003-11-13T00:13:16

I don't know if the spanner range stuff in Net::CIDR::Lite would've helped you any, but there it is on CPAN. The first part was just written just as a response to one of MJD's puzzles, and the 'find which CIDR range object(s) an IP address is in' part was written later for the fun of it. Though it doesn't 'find which range object(s) a CIDR address is in', if that's what you needed.

Re:CIDR addresses

Matts on 2003-11-13T08:10:46

This module probably does almost exactly what I've developed, with the minor exception that you're just creating one big list and not caring about a LHS and a RHS. I imagine that could be added somehow if I were so inclined (but I'm not, since my code works now :-)

It also probably uses a lot more RAM than mine. I tried to keep everything on disk because of the sheer volume of IPs (totaling just over 2 million). We tried to do everything in RAM but it used about 600M of memory, which is too much on an already loaded server.

Re:CIDR addresses

runrig on 2003-11-13T22:16:09

One of MJD's test files had 65536 separate but contiguous x/32 CIDR addresses to merge. If addresses's are contiguous then the middle node is deleted, and the hash object is left with just the start and end of the joined range. If ranges are overlapping, then periodic calls to 'clean' will eliminate the overlapping nodes. If you have many completely separate ranges, then yeah it'll take alot of memory. I'm not sure what you mean by LHS and RHS though (well, I know what they mean, but not the context here :-)

And the original 'puzzle' was posted here if anyone's interested.

Re:CIDR addresses

Matts on 2003-11-14T07:59:41

Ah, by LHS and RHS I mean that say I'm merging lists A and B, I assign 0.0.0.2 to A, and 0.0.0.4 to B, and where I get overlaps I expect to find 0.0.0.6. This has to work for multiple such lists.

Re:CIDR addresses

runrig on 2003-11-15T13:35:15

I assign 0.0.0.2 to A, and 0.0.0.4 to B, and where I get overlaps I expect to find 0.0.0.6

Ah, then (I think) it would've been easily doable with Net::CIDR::Lite, though what you ended up with is probably more efficient speed and memory-wise, especially if there are alot of lists (and I admit the docs of N::C::L are lacking).

Instead of merging the lists, you'd create a 'spanner' object (dumb name, but I didn't know what else to call it), where the labels are the Socket::inet_aton() of what you want assign to each list, then you can do a $spanner->find(@bunch_of_ip_addresses) and get a hash back of the ip adresses each associated with the lists in which they were found.

Then you can a List::Util::reduce { $a | $b } on the lists of each found address. You're probably all done with it now, but it'd be interesting to know if you ended up with the same results in anywhere near the same amount of time :-)

Happy Cycling?

tomhukins on 2003-11-13T01:28:29

I used to cycle to/from work - it made me feel alert and healthy. As for showering, I cycled in the winter and always spent 10 minutes or so cooling of in my cycling gear, then changed into work clothes.

I didn't last more than half a year because I took a corner too fast and broke both my arms. Given that I'd already come off my bike due to poor cornering (which left me picking gravel out of my back in the shower) a few years beforehand I decided to give up.

I've told quite a few people this story and been surprised by the number of people who have had nasty cycling accidents due to clumsiness. People make a big deal of the health benefits and often ignore the risks of cycling. Take care!

Re:Happy Cycling?

Dom2 on 2003-11-13T18:07:25

At this time of year, the main health risk is idiots in 4-wheeled tin cans who pull out without seeing you. I try to be bright at night, but there's only so much you can do without pulling a battery on a trailer behind you...

-Dom

Re:Happy Cycling?

hfb on 2003-11-15T19:48:59

You should have a look at some of the new CatEye bright white LED battery powered headlights. They're so bright that they make me feel silly for getting one of the hub dynamo systems. :)

Bitwise string ne bitwise integer

bart on 2003-11-16T00:43:31

I would bitwise combine 2 and 8 and get ":". Yes, I was confused too.
You must have used two strings. Bitwise combination of two strings is different in Perl, than of integers. In fact, if any operand is a number, Perl will try to convert the other argument to a number, too.
print "2" | "8";
Result:
:
vs.
print 0+"2" | "8";
Result:
10

In the case of strings, Perl will bytewise combine the bits of the bytes of which the strings consist. For numbers, Perl just combines the integers, commonly 32 bits each.

Re:Bitwise string ne bitwise integer

Matts on 2003-11-16T10:45:34

I couldn't find this documented anywhere. Is it?

Re:Bitwise string ne bitwise integer

bart on 2003-11-16T20:06:10

There's the entry on "Bitwise String Operators" in perlop.