Sunday, April 29, 2012

2D Rectangular Collison Detection

I was just looking through some old code and came across something I couldn't quite work out in my head but had to find. Circles was very self explanatory, but rectangular shapes are a bit more awkward, so here's a simple way that will return either a true or false based on the idea that 0 is false and a number greater than 0 is true, assuming rectangle 1 is made of points a and b and rectangle 2 is made of points c and d.
Points relative to rectangle (showing collision)
We also assume each point is a list of the [x, y].

int checkCollision(int a[], int b[], int c[], int d[]) {
    int c1, c2, c3, c4, c5;
    c1 = a[0] < d[0];
    c2 = a[1] < d[1];
    c3 = b[0] > c[0];
    c4 = b[1] > c[1];
    c5 = c1 && c2 && c3 && c4;
    return c5;
}

That would (more or less) be the gist of detecting if 2 rectangles collide by finding if there is an overlap. The basic idea is make sure all the points are in an area they could  be in if there was an overlap. Then by making sure all are in an area they can be in if there is an overlap, detects the overlap, since all must be in those areas for an overlap to exist. For any other shapes that are not square, you must use trigonometry, which I may get into some day down the road.

Monday, April 16, 2012

MyBB nofollow external links

In the spirit of looking into SEO a bit and messing around with regex a lot more, I decided to do some SEO over on a forum I code at. They use MyBB. I dug up a plugin for this, however it was less than spectacular. The problem was it would add rel="nofollow" to internal links as well, and even replace anywhere in the message you saw target="_blank" with target="_blank" rel="nofollow". This can be a problem telling a crawler not to follow internal links, so I decided to re-write the plugin. It will not alter internal links and can recognize both http and https internal linking.

[Download v1.0]

Maintained: https://github.com/anarchywolf46/MyBB-Plugins

Thursday, April 12, 2012

Minecraft /dev/input/event error

I've been playing Minecraft for a while, and having a computer with Ubuntu, that's what I play it on. However I kept running into a series of error messages about /dev/input/event. Since everything ran fine, I never bothered to see what the error was about. Today I finally searched around and it was a problem with file permissions. A quick command to fix it is sudo chmod go=u /dev/input/event*.

A quick explanation of what it does if you don't understand it, it will copy the permissions for the root (u)ser to the (g)roup and (o)ther, other being anyone else not in the group or that user.

Tuesday, April 3, 2012

CSS3 ::selection

While working on some stuff I cam across a CSS3 pseudo-class selector called ::selection. While this is something you can do in javascript, it makes things a lot easier when styling can all be done in CSS rather than javascript workarounds. The javascript equivalent would be rather annoying to do. So the CSS3 way, as with any CSS, is rather simple and quick to do, minus a few catches here and there. CSS3 still lacks a good deal of support and isn't good if you want some real backwards compatibility, however I'm more interested in how to use this to just screw with things in ways it could be exploited, bad or just annoying and this particular property hit right on the head for some annoying fun.

You may wonder how this could be annoying, and quite simply, think about what would happen if selected text disappears. It would no longer be selected and then have to reappear, unselected. Thus the end result is text you cannot highlight without altering the CSS. So the code for that looks something like this.
::selection {
  display: none;
}
::-moz-selection {
  display: none;
}

I've only tried this in Firefox 10, but when I do it on Firefox, the text is impossible to highlight, however I can drag the text. As to the effects it will have in other browsers that support it, well that's all part in the fun in trying to mess with things to get results like this.

Try to highlight this and see what happens if your browser supports it.

Tag Cloud

.NET (1) A+ (1) addon (6) Android (3) anonymous functions (5) application (9) arduino (1) artificial intelligence (2) bash (3) c (7) camera (1) certifications (1) cobol (1) comptia (2) computing (2) css (2) customize (15) encryption (2) error (15) exploit (13) ftp (2) gadget (2) games (2) Gtk (1) GUI (5) hardware (6) haskell (15) help (5) HTML (4) irc (1) java (5) javascript (20) Linux (18) Mac (4) malware (1) math (8) network (5) objects (2) OCaml (1) perl (4) php (8) plugin (6) programming (42) python (24) radio (1) regex (3) security (21) sound (1) speakers (1) ssh (1) telnet (1) tools (11) troubleshooting (1) Ubuntu (3) Unix (4) virtualization (1) web design (14) Windows (6) wx (2)