29 Dec 2012

Trello-Archiver from Scratch

Trello-Archiver is a set of Ruby scripts that allows one to export their Trello board into a CSV, TSV, or XLSX file. It was started by another person on Github.com named Mad_Typist. Early on in the process I sent them a pull request to contribute my changes back… but they don’t seem to be around. Given that, I’ve forked the project and continued to develop it for my own benefit.

Trello-Archiver relies on a few conventions that exist in the Ruby world. 1. Project dependencies are managed with Bundler 2. A semi-recent version of Ruby is used >= 1.9.2

To use the project on a system that isn’t setup for Ruby development, the first step is to install a recent version of Ruby. I prefer to use a tool called Ruby Version Manager for this RVM.

Install a sane Ruby Version Manager along with Recent Rubycurl -L https://get.rvm.io | bash -s stable --ruby

Source the installed script to allow for using RVM this first time w/ this command: source ~/.rvm/scripts/rvm

Future logins will automatically source RVM using your bashrc or zshrc.

The next step is to clone the Trello-Archiver repo from Github.

Then cd trello-archiver and run bundle install. Bundler installs the necessary dependencies for Trello-Archiver. The nice feature about Bundler is that it manages individual projects’ dependencies independently :).

Next, cp config.example.yml config.yml. Config.example.yml is the template for where the authentication credentials are stored along with any default settings.

Open up config.yml with your favorite text editor. Instructions are inclosed in there for how to gather your secret credentials from Trello.com.

First, open https://trello.com/1/appKey/generate in your web browser. Copy the first key as your ‘public key’ and the second (longer) key as your ‘private_key’.

Next we need to enter those values into a special url: https://trello.com/1/connect?key=PUBLIC_KEY_FROM_ABOVE&name=ANYNAME&response_type=token&scope=read,account&expiration=never The two values that need replacing in this URL are PUBLIC_KEY_FROM_ABOVE nd ANYNAME. ANYNAME is a placeholder for any text that you want to use to identify this key, ie it could be TrelloArchiver. Also note that this is authorizing Read-Only access. This way, even if there’s a bug in the software the token won’t allow changes to your Trello information.

Past that value into your web browser and click allow on the confirmation webpage.

The following page that loads has your ‘access_token_key’. Copy this value into your config.yml. Save config.yml and exit to commandline.

That’s it for authentication setup! Make sure to be careful with this config.yml and don’t go adding it to any public git repos ;).

Now for backing things up :). Decide if you want a specific board backed up or all of them.

Let’s backup a single board: -ruby bin/trello_backup.rb -Choose your board by number and hit enter -Enter a filename or not (it defaults to name of board and date stamp) -Defaults to exporting as XLSX (this is easily changed in script).

Now let’s backup all the boards: -ruby bin/trello-autoarchive.rb -Sit back and wait for it to finish! -It’s set to backup all boards with default names and using XLSX filetype.

Caveats: It saves these files into the current folder. Apparently I broke CSV functionality with some recent changes. I’ll get it working again. The spreadsheet structure is what works for me. If you need a different configuration, please let me know and I’ll look into it. Not all info is backed up. For full backup, download your JSON export from Trello. The main thing that I didn’t include in Trello-Archiver is a set of timestamps for when a Card is moved to each List. This could be a future feature if others have a need for it.

Below is a Gist showing the shell commands

25 Dec 2012

RCodeTools - How to get them working in VIM

RCodeTools is an add-on for popular neckbeard text editors such as VIM and Emacs. (My preference currently being VIM). I came across it through RubyTapas Screencasts by Avdi Grimm. He uses it extensively in his screencasts for crystal clear explanations and live displays of code execution.

RCodeTools adds hash comments (ie #=\>) to the text editor buffer. Then when another command is executed, the whole buffer is evaluated and the area beyond the hash comment is populated with the output from that specific line(s) of code.

It’s remarkably helpful for explaining and demonstrating code because it avoids any context shift. The comments serve to demonstrate the code’s state at any given moment!

Avdi Grimm uses RCodeTools inside Emacs in the screencasts and I was eager to begin using RCodeTools myself. I had difficulty getting the plugin to work in VIM, resulting in attempts to reinstall VIM, modify the $PATH, etc.

Turns out there is a simpler way: 1. Install RCodeTools into your ~/.vim/ folder. Specifically this means the vimscript files. 2. Install vim-rvm for managing path. 3. Gem install rcodetools inside your standard RVM ruby. 4. Add mappings to VIMRC. Included are my mappings (which are recommended by the README.vim)

I look forward to putting this addon to good use at future CodeRetreats! And it’s the perfect compliment to screencasting.

Thanks Avdi for drawing my attention to this wonderful tool.

24 Dec 2012

Ruby Off The Rails - Ep. 1 -- Zero to Ruby -- Pt. 2

Here’s the second installment, briefly covering installing RVM and an approachable text editor (Sublime Text 2). I advocate for focusing learning on one area at a time which means learn Ruby rather than starting to learn Ruby and VIM at the same time. (Learn VIM or EMACS once you’re further along with the language itself and see it as a long term investment in your productivity and happiness as a code crafter). Ep. 2 – Zero to Ruby – Pt. 2 Ruby Off the Rails - Ep 2. - Zero to Ruby Pt. 2 from ZPH on Vimeo. Here’s the source for the commands used in the episode:

23 Dec 2012

Ruby Off The Rails - Ep. 1 -- Zero to Ruby -- Pt. 1

Ruby Off The Rails is a new series of screencasts that I will be publishing. The first cluster of videos will address the problem of getting started with Ruby development by using a virtual installation of Ubuntu Linux running inside Virtualbox. It’s simpler than it sounds and it preserves the integrity of your everyday system. Here’s the first installment, enjoy! (I recommend opening the video for fullscreen display to better view the text)

Ruby Off the Rails - Ep. 1 - Zero to Ruby - Part 1 from ZPH on Vimeo.

Commands from Ep. 1

22 Dec 2012

JDBC, MsSQL, and JRuby, Oh My!

I was recently in a position of needing to access information from a legacy database on a Microsoft SQL Server ( 2005 ). Since I’d prefer that the contact came from a *NIX system (probably Ubuntu), I checked out ODBC and JDBC as options. Based on a couple of blog entries by fellow Rubyists and ODBC users, the ODBC configuration files add an extra layer of complexity for the database connection. I chose to do it with JDBC because it allows those settings to be configured in the script/config itself. Also, with the sqljdbc*.jar running on the JVM we have platform independence. Now, on to the implementation:

  • On the SQL Server box
  • Allow mixed authentication (it appears that JDBC does not interface with Windows User credentials based on cursory research)
  • Setup a unique SQL Server Auth User who has the appropriate degree of authorization on the database. Consider read-only if your application is limited to querying the DB rather than writing to it. This will limit the risk of inadvertent writes.
  • Depending on setup, you may need to open ports 1433 and 1434 on the SQL Server’s firewall. If possible, only do this step on an internally facing instance of the SQL Server. (Less attack surface to the internet is a good idea).
  • Test the connection by using SQL User authentication when connecting with the builtin Microsoft SQL Server Management program. If all goes well, this tells you that it’s configured correctly when accessing from the same system. Next to connect from a remote system. You’ll need the following pieces of information: the database’s name, the database ip address, the database instance name (ie defaults to SQLEXPRESS when using SQL Express), the Sql username and password
  • On the remote system (the Linux box)
  • Download and extract the following file from Microsoft, this is the JDBC adapter file that they provide http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=21599 OR the direct link at the time of this article: http://download.microsoft.com/download/D/6/A/D6A241AC-433E-4CD2-A1CE-50177E8428F0/1033/sqljdbc_3.0.1301.101_enu.tar.gz Extract that into a convenient place in near where your connection code exists. I chose to use a standard Ruby project layout as follows: |-- Gemfile |-- Gemfile.lock |-- Guardfile |-- README.md |-- bin |-- features |-- jars | |-- sqljdbc.jar | |-- sqljdbc4.jar |– sqljdbc_3.0.1301.101_enu.tar.gz |– lib | |– README | |– jruby_demo.rb | |– tds_demo.rb |-- demo.rb |-- spec – spec_helper.rb 7 directories, 16 files Notice that the sqljdbc\*.jar files are inside jars which is on the same level of nesting as the lib directory. This is important when referencing their location in the code. Then install JRuby if not currently installed. I use [RVM](www.rvm.io) for easy Ruby switching. (Thanks to Keith Burnett for posting a comment indicating that this portion was out of order... silly me!) Once the JARs are extracted, runbundle install` to request that Bundler install the required dependencies. Next modify the following script to help you get started. Note that you’ll need to replace the values of the CONSTANTS as appropriate for your IP addresses, username, passwords, etc.Of further note is that a class will need to be defined for each table in the database that you wish to access. I briefly outline this in the comments of the code. This is fairly standard ActiveRecord use. Questions, comments, post them here or to me on Twitter @_ZPH.

18 Dec 2012

Refactoring... a Weighty Question

I’ve been working on a library for easily exporting Trello information to CSV, TSV, and XLSX. It’s currently working well for all three formats although the code itself is first or second draft quality. (Not that XLSX has some issues of its own when done from Ruby. I’d like to solve it eventually but it’s on the back seat since the files still open.) I took the time to import it into CodeClimate’s automated test system to see where potential issues are. It revealed that one particular set of methods was far too complex. These were the methods that generate the CSV or XLSX file. I sat down to refactor them while under the weather this weekend and here’s what I accomplished: -Extracted code out into methods (needs more of this as methods don’t have single responsibilities) -Abstracted the process into a single uber method that calls sub methods (could be private methods later in development) -In order to abstract the process to be identical for CSV and XLSX, I found one spot that needed an eval(content) statement. ( Perhaps in the future I can adapt a lambda to better suit this purpose?? ) Here are the different versions of it: Before-After-Diff-Looking at it again I want to extract the different classes into their own files for better compartmentalizing the code. Let me know in the comments what code smells are present or what refactorings are still advised.

16 Dec 2012

Easy SSH Tunnel on OSX

I recently found myself working from a restaurant with open WIFI. After having someone on open WIFI snatch my Facebook credentials back in 2009, I’ve become understandably paranoid about security on unsafe connections. I spent a few minutes setting up a Squid Proxy on my VPS, when I came upon a better solution: set a SOCKS Proxy in OSX and create an SSH tunnel.

How it works

The SSH tunnel connects to the VPS using an encrypted channel. This is open for use on a localport such as 8080 (or a randomly assigned one w/ script). The SOCKS Proxy passes network requests to the localport instead of sending them to the web/email-server/etc.

How to do it

On OSX it consists of the two following steps: sudo networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 $localport off ssh -f -p $remoteport -D $localport $remoteuser@$remoteproxy sleep 1d This is all well and good, but someone went to the trouble of wrapping this in a script: OSX-PROXY. I took a little bit of time this weekend and refactored the code to extract functions, utilize a case statement, and add extra commandline arguments.   My revised script also toggles the state of the proxy if no arguments are given.

Update

The aforementioned code works very well but I’m not sure if it re-routes all DNS requests which could divulge personal information. So I switched to this python library that re-routes all activity and is more established: SShuttle. Add an alias to the shell for quick starting with default settings: [code]alias sshuttle_start=’sshuttle --dns -vvr user@vps 0/0' [/code](Replace user and vps placeholders with the appropriate info). PS - Never ever trust public or semi-public Wifi.  Using a proxy like this is the minimum security that you should consider.

15 Dec 2012

rcodetools and VIM

I’ve been listening to RubyRogues which introduced me to Avdi Grimm from the Ruby community. I’ve also been subscribed to his RubyTapas screencast series which is a 2x a week Ruby show.

He uses a neat tool called rcodetools to execute Ruby code from within an Emacs buffer. Unfortunately, it wasn’t working when I tried to use the VIM counterpart, with segfault codes showing up. Here’s the fix: ( I’m using RVM to manage my Ruby Versions ) *Install Tim Pope’s excellent rvm extension for VIM cd ~/.vim/bundle git clone git://github.com/tpope/vim-rvm.git

*Install rcodetools using RVM gem install rcodetools

*Remove keybindings in other programs (ie Dashboard & Expose) for F10, F11, F12 or rebind the keys per README.vim

Now enter a VIM file and type F12 on any lines that you want the output from followed by F11 to evaluate the whole file. If you want to only re-evaluate the current line use F10 instead of F11.

It’s a great tool for terminal screencasting! Thanks Avdi for letting me know that this tool is available.

26 Nov 2012

Script to Update Sandy Knolls Metes and Bounds Software on OSX

After frequently finding myself not using the current version of Metes and Bounds, I wrote a Ruby script to automagically do that very thing.  It checks current version, downloads the current version, and installs it into /Applications (BEWARNED, it nukes your current version of Metes and Bounds.app, use at your own risk):Thanks to this random blog for the hint on mounting DMGs from commandline!

01 Nov 2012

Migrating NeoRouter Server to new VPS

Migrating from a flaky VPS to a more reliable one has generally been a hassle. But one easy part was migrating NeoRouter Server to a new Xen VPS. tar -zcvpf OUTPUT\_FILENAME.tar.gz /usr/local/ZebraNetworks/NeoRouter Rsync or scp that file over to new VPS wget http://download.neorouter.com/Downloads/NRPro/Update\_1.6.3.3150/Linux/Ubuntu/nrclient-1.6.3.3150-pro-ubuntu-amd64.deb sudo dpkg -i nrclient-1.6.3.3150-pro-ubuntu-amd64.deb Decompress file into place in /usr/local… etc Log into NeoRouter dashboard and redirect domain to new IP address (as found by running ifconfig on NeoRouter Server VPS) Save dashboard settings, click ‘Domain Status’ tab, and gloat in your success!