How to setup an OpenWRT router as a WiFi bridge to an Ethernet router

You can use an OpenWRT router or access point to connect WiFi enabled devices to a router, which only has wired Ethernet. For this to work, I am assuming you already have an access point or router running OpenWRT, in this case version 12.09, Attitude Adjustment.
Log into your router, using the LuCi frontend, and go to the Network/Interfaces tab:

There you should see your LAN device. Edit it to have an appropriate IP address from your local subnet. Most often your network will be 192.168.0.0 and your existing router will have the IP 192.168.1.1. But your mileage may vary…

Lets put in a static IP address, so we can find our router in case something goes wrong. Also make sure to set the netmask (in this case 255.255.255.0), gateway and DNS server (both probably should point to your router, 192.168.1.1).

Now go to the Physical Settings tab. Here, it’s important to check “Bridge interfaces” and to select both the ethernet adapter, most likely eth0, and the wireless network. One of the ethernet devices will say “wan”, if your are using a router instead of an access point for this. You don’t want that device.

Hit “Save & Apply” when you are ready. And be sure to have the de-bricking guide ready, if something goes wrong…

How to run tmux via ssh instantly

With my Raspberry Pi, what I do very, very often is this:

localhost$ ssh raspberrypi.local    # Here I already type the next command and wait a while
raspberrypi$ tmux attach

This is all well and good, but sometimes the Pi is down, and I will attach to one of my local tmux sessions. Very annoying. Instead you could try to do this:

localhost$ ssh raspberrypi.local tmux attach
not a terminal

Well, that did no good. So a look at the man-page of ssh or a quick search reveals this gem:

localhost$ ssh raspberrypi.local -t tmux attach

This allocates a pseudo terminal, which is needed by tmux to function correctly. This is also done by ssh, if no command is given, but a login shell is spawned.

Some tmux cheats

There’s a lot of stuff you can do with tmux. Here are some nice to know things:

  • C-b C-o: cycle contents of current windows (or swap if there are only two windows)
  • C-b C-SPC: switch between vertical and horizontal split
  • C-b n, p: next or previous screen
  • C-b [: copy mode
    • Use Emacs bindings to copy and paste:
    • C-SPC: begin selection
    • C-w or M-w to copy
  • C-b ] to yank (paste)

    How to copy Mails from iCloud to GMail

    You can use the fabulous imapsync tool to copy mails between IMAP servers. For example you can copy a certain folder from Apple’s iCloud to Google’s gmail:

    imapsync 
    --noauthmd5 --ssl1 --ssl2
    --host1 mail.me.com --user1 'your.icloud.name'
    --host2 imap.gmail.com --user2 'your.gmail.name@googlemail.com'
    --folder 'your/folder/to/be/copied' --sep1 '/'
    --prefix1 '' --prefix2 '[Google Mail]' --sep2 '/'

    The important parts here are the user names for the IMAP servers. Note that you need to generate an application specific password, if you are using Google two factor authentication! Also important is the “[Google Mail]” IMAP prefix.

    Edit: It seems gmail has a weird interpretation of all the IMAP folders and stuff. Since they are using labels, the above script might create a weird label for the copied emails, but they will be there nevertheless!

    Working around connection problems with Emacs Tramp

    From time to time I have to edit files on a SunOS 5.10 server. I use Emacs with tramp for this. However, after some time I get this error message from tramp:

    File error: Couldn’t find exit status of `test -e …

    It seems that the ssh connection goes bad for some reason. After this you won’t be able to save the file anymore. You can work around this by running M-x tramp-cleanup-all-connections and then saving again.

    There are approximately N/ln(N) primes between N and 2N

    Just saw this very nice video by @numberphile, and thought I whip up a small Python program to demonstrate the prime number theorem:


    #!/usr/bin/env python
    #
    # "Chebyshev said it, and I say it again: There's always a prime between n and 2n."
    #

    import sys
    import math

    class PrimeFinder:

    def __init__( self, n ):
    self.n = n

    def isNPrime( self, N ):
    for x in range( 2, int( math.sqrt( N ) ) + 1 ):
    if N % x == 0:
    return False
    return True

    def computeAllPrimesBetweenNAndTwoN( self ):
    result = []
    for N in range( self.n, 2 * self.n + 1 ):
    if self.isNPrime( N ):
    result = result + [ N ]
    return result

    def main():
    if len( sys.argv ) != 2:
    print "Prints all prime numbers between N and 2N"
    print "Usage: %s N" % sys.argv[ 0 ]
    print "Where N is some positive, natural number."
    sys.exit( 0 )

    N = int( sys.argv[ 1 ] )
    primeFinder = PrimeFinder( N )
    allPrimes = primeFinder.computeAllPrimesBetweenNAndTwoN()
    print "There are %u primes between %u and %u: %s" % (
    len( allPrimes ), N, 2 * N, str( allPrimes )[ 1 : -1 ]
    )

    if __name__ == "__main__":
    main()

    And it seems to work, but check WolframAlpha if you don’t trust me 🙂


    $ ./myprimes.py 100000
    There are 8392 primes between 100000 and 200000: 100003, 100019, 100043 ...