🕹ī¸ Do Something Great! 😄

Category: Geek

  • 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.

  • Jumping to multiple hosts with ssh behind a gateway

    At home I have several hosts that I need to ssh into at various times. Unfortunately, since IPv6 is widely deployed, I am stuck sshing into one host that is publically accessible, and from there sshing into other hosts. Cumbersome to say the least, but it does look cool when I’m showing it off.

    Anyway, you can automate the connection with netcat on the gateway host. I like to put my ssh commands into my ~/.ssh/config file so then I don’t have to remember anything. To jump to an internal host from the gateway I add the following to my ~/.ssh/config file on the client (most notably, my 2010 MacBook Pro).

    Host macmini
        hostname LOCALIP
        user gadmin
        ProxyCommand ssh USER@GATEWAY nc %h %p
    

    Replace LOCALIP with the address of the host to which you want to jump, and replace USER@GATEWAY with the gateway’s username and address. You can use other hosts defined in your ~/.ssh/config file, so if you have a host for GATEWAY, you can use it.

  • Resetting a .taskpaper file

    I use a couple of .taskpaper files for checklists of things that need to be done every day. In it, after a task is completed the task gets an @done tag added. But the next day I want to start fresh. I could do a find/replace, but sed at the command line works better:

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

    Adding the above alias to my ~/.bash_profile adds the ability to reset a taskpaper file with a simple rst FILE.taskpaper. Under OS X, the -i parameter requires an extension for a backup file. You can simply have ” to set it to nothing and then a back up file won’t be created.

  • My Newsbeuter config file

    And here’s my config file that I use with Newsbeuter.

    article-sort-order  date asc
    auto-reload         yes
    reload-time         60
    show-read-feeds     no
    show-read-articles  no
    mark-as-read-on-hover   no
    bookmark-cmd        "~/Development/bookmark"
    bookmark-autopilot  no
    save-path           "~/Documents/Research"
    
  • Using RSS like it’s 1990

    I’m a big console fan, preferring to do as much work as possible from the command line. So it shouldn’t be surprised that I also use RSS even as others have abandoned it for things like Twitter. I prefer to supplement my news feeds with Twitter and not replace it.

    Since the demise of Google Reader, I’ve settled on Feedly as my RSS reader. It’s web interface has keyboard shortcuts, and the Reeder app works very well on my iPhone and iPad. But I think it could be faster

    Back to 1990

    Before web forums were all the rage, there was Usenet News. It was international, and distributed, which made it very resilient. It was also, for the most part, limited to text interfaces. There were several GUI interfaces for accessing Usenet, but for me, the command line application tin was all I needed. With it I could navigate an alarming amount of posts, selecting the ones I wanted to read while ignore the rest. It was pretty amazing how fast the whole process was. Alas, speed is something we lost on the transition to graphically interfaces.

    Enter Newsbeuter

    Newsbeuter is an open source command line RSS reader that can run on most UNIX based operating systems. A simple sudo apt-get install newsbeuter installed it on my Ubuntu host, and I was good to go. I’m still in the honeymoon phase, so we’ll see how long it lasts. To see it in action you can check out the screenshots on the Newsbeuter site.

  • Publishing using Sphinx to Github

    I’ve been playing around with Sphinx as a digital publishing tool. It can take multiple files written in reStructuredText (similar to Markdown, which is plain text with minimal markup) and create not only a website, but also PDFs and ePubs (and more, list is on the website). An example is the Sublime Text Unofficial Documentation. If you click on the Read the Docs link in the bottom left of the window, you can see the documentation in other formats.

    Read the Docs will automatically create a website and other files from a Github repository, but you can also publish yourself to Github without using another service. My problem came from an issue with Github ignoring the folder _static, which is where Sphinx puts assets for the website. The solution is simple enough, have a .nojekyll file in the root of the website. The question was how to do that automatically. What I did was add a new target to the Makefile[1]:

    github:
        $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
        touch $(BUILDDIR)/html/.nojekyll
        ghp-import $(BUILDDIR)/html/
        git push -u origin gh-pages
        @echo
        @echo "Published to Github"
    

    Now when I type make github, the website will be rebuilt, a .nojekyll file will be created, the website will be imported into the gh-pages branch and that branch will be pushed to Github.

    [1]: This assumes you have already set up authentication to push a branch to Github and have installed ghp-import.