Wishful Coding

Didn't you ever wish your
computer understood you?

Hidden Pages in Wordpress

More often that not, I need to hide pages from the menu and search pages, when setting up a Wordpress blog.

Usually for download and thank-you pages, or other stuff that is only accessible via a direct link.

By default, Wordpress includes a visibility settings, which has 3 values.

  • Public – anyone can see it.
  • Protected – Anyone with the password can see it.
  • Private – Only you can see it

None of them is useful for my goals, however, some digging revealed that a small change would allow you to link directly to password protected pages.

Copy wp-pass.php to unlock.php, and make the changes below.

--- wp-pass.php	2011-09-19 05:17:26.000000000 +0200
+++ unlock.php	2012-01-02 17:38:47.000000000 +0100
@@ -10,8 +10,8 @@
 require( dirname(__FILE__) . '/wp-load.php');
 
 // 10 days
-setcookie('wp-postpass_' . COOKIEHASH, stripslashes( $_POST['post_password'] ), time() + 864000, COOKIEPATH);
+setcookie('wp-postpass_' . COOKIEHASH, stripslashes( $_GET['post_password'] ), time() + 864000, COOKIEPATH);
 
-wp_safe_redirect(wp_get_referer());
+wp_safe_redirect($_GET['return']);
 exit;
 ?>

Now you can simply link to http://example.com/unlock.php?post_password=foobar&return=/thank-you/

Published on

Awesome Tower Defense Robot

I found this robot on Youtube, and guess what? It comes with building instructions and software.

I’m still working on my own building instructions, but now you have something to play with.

Happy new year!

Lego NXT With a Gamepad

I built this robot a while back, but I can’t stand the software that comes with the NXT, my own compiler isn’t ready yet, and any other remote controls I found didn’t work particularly well, if at all.

If you want it done right, you have to do it yourself – Bernd Paysan

So I threw together PyGame and nxt-python, and wrote my own little application to control the NXT. Notice that it looks very similar to this PyMouse code

I have no building plans for the robot, it’s the standard wheel base with my own pincer. I do have the code:

import pygame
from nxt import locator, motor
from time import sleep

# edit this to reflect your joystick axis and buttons
axis = {'x':0, 'y':1, 'x*':3, 'y*':5}

b = locator.find_one_brick()

left = motor.Motor(b, motor.PORT_B)
right = motor.Motor(b, motor.PORT_A)
action = motor.Motor(b, motor.PORT_C)

closed = False

def limit(nr):
    if nr > 50 or nr < -50:
        return min(127, max(-128, nr))
    else:
        return 0

def move(fwd=0, turn=0):
    lp = int((fwd - turn) * -100)
    rp = int((fwd + turn) * -100)
    left.run(limit(lp))
    right.run(limit(rp))

def pincer(button):
    global closed
    try:
        if button and not closed:
            closed = True
            action.turn(-40, 70, emulate=False)
        elif not button and closed:
            closed = False
            action.turn(30, 70, emulate=False, brake=False)
    except motor.BlockedException:
        print action.get_tacho()

pygame.init()
j = pygame.joystick.Joystick(0) # first joystick
j.init()
print 'Initialized Joystick : %s' % j.get_name()
try:
    while True:
        pygame.event.pump()
        sleep(0.1)
        
        # get_axis returns a value between -1 and 1
        move(j.get_axis(axis['y']), j.get_axis(axis['x']))
        pincer(j.get_button(0))
        
except KeyboardInterrupt:
    j.quit()