đŸ•šī¸ Do Something Great! 😄

Author: ryan

  • Finding your Pi on the network

    When you’re playing around with the Raspberry Pi, there are multiple times when you won’t have a screen attached to the Pi but you’ll want the IP address to use with SSH. What I did was set up static IP addresses on my DHCP server (in this case the ASUS RT-AC66U$).

    Click on LAN on the left side, and then select the DHCP tab:

    Manual IP Management

    Enter the MAC address of the network port on the Pi and select an IP address that isn’t being used. You’ll probably want to enter the MAC address of the wifi dongle too, if you use that. The ASUS is nice because the drop down will contain the MAC addresses of the devices that have connected to it, so you should be able to go through that list until you find the correct entries. To get the MAC addresses if this method doesn’t work, ssh to the pi and run ifconfig | grep HWaddr. It will then show the network interfaces and their MAC addresses.

    Once you have it set up, it’s really nice playing around with your Pis. It doesn’t matter what SD card you put in, as long as the Pi is set for DHCP, it will always be assigned the IP address you set.

    $ – Affiliate link to Amazon. Non-affiliate link.

  • A bash script to check domain expirations

    I have a bad habit, and that’s of buying domain names. I have about 20, with several different registrars. If I was smart, I would consolidate them under one registrar, but, even then, checking expirations on the domains is a pain. I usually have autorenew turned on, but I still like to know when they are getting close to expiration.

    Before re-inventing the wheel, I did a Google search, and found Domain Expiration Check Shell Script. It worked pretty well, except for a few top level domains like .me which didn’t work. I modified the script, and just had to put some finishing touches on it today (.com, .net, and .org was broken). Check out the gist of the script on Github.

    I put all of my domains in a text file, and can then run it with ./domain-check -f mydomains.txt. It’s pretty cool.

  • Set your Raspberry Pi up for Wifi roaming

    I’ve had a Raspberry Pi 2 just sitting around for several months, waiting for a purpose. Since I haven’t come up with a purpose, I decided to make it a portable headless Linux box that will travel with me, connect to Wifi automatically, and eventually, hopefully, set it up as a Piratebox. First things first, lets get it connecting.

    It was easier than I thought it was going to be to set it to automatically connect. Basically, I modified /etc/network/interfaces to add a roam configuration for wpa supplicant.

    # Include files from /etc/network/interfaces.d:
    source-directory /etc/network/interfaces.d
    
    auto lo
    iface lo inet loopback
    
    iface eth0 inet manual
    
    allow-hotplug wlan0
    iface wlan0 inet manual
        # wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
        wpa-roam /etc/wpa_supplicant/wpa_roam.conf
    
    allow-hotplug wlan1
    iface wlan1 inet manual
        #wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
        wpa-roam /etc/wpa_supplicant/wpa_roam.conf
    

    I just added the two lines that start with wpa-roam and commented out the default wpa_supplicant.conf lines. Next up was to create the /etc/wpa_supplicant/wpa_roam.conf file:

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    network={
            ssid="home"
            key_mgmt=NONE
    }
    network={
            ssid="iPhoneHotSpot"
            key_mgmt=WPA-PSK
            psk="PASSWORD"
    }
    

    Adjust the parameters for your networks. Plugging the Pi into the network and manually running sudo ifdown wlan0;sudo ifup wlan0 is how I tested it.

    Finally, the pi needs to see if it doesn’t have a network connection, and if it doesn’t, bring wlan0 and then back up and see if it will connect. My wifi dongle (the Edimax EW-7811Un) is on wlan0, so you may need to modify. I set a crontab (sudo crontab -e) with the following line:

    * * * * * /bin/ping -q -c2 8.8.8.8 || (/sbin/ifdown --force wlan0 ;/sbin/ifup wlan0 )
    

    Every minute the Pi will send out two pings to Google’s DNS servers, and if it doesn’t get a reply, it will take the connection down and bring it back up. Now I have a Pi that will autoconnect to wifi.

  • Fixing my .taskpaper reset alias for bash

    There was a little problem with my alias to reset a .taskpaper list by removing all of the @dones. It didn’t remove any spaces before the @done, so each line would gain a space every day. This fixes it:

    alias rst="sed -i '' 's/ *@done\(.*\)//g'"
    

    Now it removes one or more spaces that could be before @done.

  • Switching terminals in tmux with ALT-numbers

    I’m a big tmux fan, switching from screen a few years ago. Lately, I’ve been working on ways to switch between terminals faster. Now I’m using the ALT (Option key actually) under OS X to switch between the different terminals. The switching starts with the backtick and goes across the upper row of the keyboard until the equal key for 12 terminals, and then continues on with the second row and the Q key up until the I key for terminal 20. It seems to be working pretty well, the biggest issue is that I can’t jump to specific buffers in Weechat with ALT-BUFFER#, but that’s not a big deal (I’m using ALT-J BUFFER# right now.) Here’s the specific section of my .tmux.conf file:

    # Use ALT-n keys to select pane
    bind-key -n M-"`" select-window -t 0
    bind-key -n M-1 select-window -t 1
    bind-key -n M-2 select-window -t 2
    bind-key -n M-3 select-window -t 3
    bind-key -n M-4 select-window -t 4
    bind-key -n M-5 select-window -t 5
    bind-key -n M-6 select-window -t 6
    bind-key -n M-7 select-window -t 7
    bind-key -n M-8 select-window -t 8
    bind-key -n M-9 select-window -t 9
    bind-key -n M-0 select-window -t 10
    bind-key -n M-- select-window -t 11
    bind-key -n M-= select-window -t 12
    
    bind-key -n M-q select-window -t 13
    bind-key -n M-w select-window -t 14
    bind-key -n M-e select-window -t 15
    bind-key -n M-r select-window -t 16
    bind-key -n M-t select-window -t 17
    bind-key -n M-y select-window -t 18
    bind-key -n M-u select-window -t 19
    bind-key -n M-i select-window -t 20
    
  • Working with Taskpaper files in vim

    I’ve been experimenting with Taskpaper for lists over the last couple of weeks, and really like the flexibility. All of my lists are stored as text files in Dropbox, which makes it easy to use/update lists from anything or anywhere. On my iPhone I use Drafts to quickly add to the task lists and Editorial to work with the tasks.

    On the desktop and laptop, I’ve settled upon using vim. Davidoc/taskpaper.vim gives me all sorts of neat ways of dealing with .taskpaper files, and has been working pretty well so far.

  • Using a Here Document with bash and MySQL

    This past week I worked on a bash script to create some input files from a MySQL database. My problem was trying to use multiple line MySQL statements, which was messing everything up. The solution was to use bash’s Here Documents. It’s a way to direct lines into a command. For me, the command looked like this:

    mysql DBNAME <<EOF
    SELECT *
    FROM table
    WHERE item = 'WhatIWant'
    EOF
    

    Everything between the two EOF would be submitted to MySQL. The next problem was that bash was trying to still interpret the MySQL statement which had backticks in it. To solve this issue, I learned that I needed to enclose the first EOF in quotes.

    mysql DBNAME <<"EOF"
    

    Bash then left my MySQL command alone, and all was right in the world.

  • Resetting a daily taskpaper list

    I have a couple daily taskpaper lists that by the end of the have an @done on each line and I need to reset it for the next day. Instead of trying to do a search and replace everyday, I added a bash alias to .bash_profile (or .bashrc):

    alias rst="sed -i '' 's/@done\(.*\)//g'"
    

    The extra '' after the -i is because OS X’s sed requires an extension for backups. Set it to nothing and OS X won’t create backups.

  • Saving bash shell history for multiple shells

    The history from the commands typed into bash are very useful from time to time, especially when I think “Oh, I’ll remember that command next time I need it”, and then I don’t. The problem with bash’s history are twofold:

    • It only saves history when the terminal exits cleanly, so if your connection drops or you have to kill the current process, you lose your history.
    • If you are running multiple terminals, or using a terminal multiplexer like tmux (my favorite!) or screen, the last bash to exit overwrites any other history with its history.

    So, after a little searching I’ve found a solution that works for me for now.

    # Save history
    #Set history suffix to the current terminal
    HISTSUFFIX=`tty | sed 's/\///g;s/^dev//g'`
    # All terminals' histories will be stored in separate files
    # in .bash_history_log. That folder will need to be created.
    HISTFILE="$HOME/.bash_history_log/bash_history_$HISTSUFFIX"
    # Time stamp the commands in the history file
    HISTTIMEFORMAT="%y-%m-%d %H:%M:%S "
    # Don't save duplicate commands
    HISTCONTROL=ignoredups:ignorespace
    # Control the size of the file
    HISTSIZE=1000
    HISTFILESIZE=5000
    # Bash will append to the history file
    shopt -s histappend
    # Bash will append to the history file after each time
    # the prompt is shown. This way it's always saved.
    PROMPT_COMMAND='history -a'
    

    Put that in your .bashrc and you’re good to go. Comments are welcome!

  • Markdown to presentation

    Since my preferred interface is the command line, yesterday I was thinking how cool it would be to knock out a presentation from Markdown. I could work on the content, and not get distracted by the interface. Luckily, I didn’t have to look any further than Pandoc. Pandoc can take a multitude of formats and convert to other formats. For example, to create a presentation from a Markdown file, a simple pandoc -t revealjs -s presentation.markdown -o presentation.html.

    Before the presentation is viewable, you need to download the reveal.js framework. Unzip it and rename the folder to reveal.js and put it in the same place as the html file created by Pandoc. You can then open the html file up in your browser and present away! The easiest way to publish the presentation publicly would probably be in Dropbox. Share the link to the html publicly and you should be good to go (your mileage may vary, I haven’t tested this yet).

    The format of the Markdown folder is pretty simple:

    % My Great Presentation
    % By Ryan Collins
    
    # Slide 1
    
    This is the content for slide one.
    
    . . .
    
    Three dots with spaces between them will pause the presentation.
    
    ## Slide 1a
    
    A header 2 will navigate *down* from the previous slide.
    
    # Slide 2
    
    Another header 1 will navigate *right*
    
    # Slide 3
    
    > - List item 1
    > - List item 2
    

    Pandoc will create a title slide from the % lines above automatically. You can also include graphics with the standard Markdown ![My great graphic](link/to/graphic.png). I’m going to play around with it more, and I also hope to find time to check out the other html5 presentation formats that pandoc works with, including DZSlides, Slidy, Slideous, and S5.