Month: May 2014

vim hacking: move set of lines into new file without buffer switching

May 30, 2014 perl and general scripting hackery , , , ,

 

Yesterday I was faced with a task where I wanted to repeatedly edit the first N lines of a file, then when they were in the form I wanted insert them into another file to be consumed by another script.  A braindead way to do this would be something like:

:0, d
:w
:e t
:$
:p
:0, d
:w
:e#

This is:

  • delete the lines from the beginning of the file to the current line.
  • save my file with these lines deleted
  • switch to my destination file to be overwritten and go to the end
  • paste in the new content
  • delete the old content
  • save this new destination file
  • return to my original file

If you only need to do this once or twice, it’s not that many keystrokes, and can be done really quickly.  However, it occurred to me that this can all be done with a one liner instead, cool enough to share:

:0,!cat > t

Here’s what happens:

  • Filter the lines from the beginning of the file to the current line through a script
  • This script has no stdout, so those lines are deleted from the current file.
  • That script uses cat to read from stdin and write the lines to a file, overwriting the destination file as desired

This is a pretty slick technique, but involves a few subtleties.  As it happens, my consumer of the moved lines was also a vim editing session, so I’m sure this was probably also possible with a split screen vim.  However, I like my screen real estate, and didn’t opt to go that route (and am not actually sure of the keystrokes required to do the same task in a split screen vim session).

Peeter Joot’s new blog: more to come…

May 21, 2014 Incoherent ramblings , , , , , , , , , ,

After 611 blog posts on my old wordpress.com hosted blog, dating all the way back to 2009, I’ve decided to ante-up and pay for more flexible hosting.

My primary motivation for this was truly geeky. I wanted the flexibility to be able to manage wordpress plugins (i.e. mathjax-latex and wolframcdf), and to also be able to put plain old html and arbitrary file content into the apache2 directory structure. I’ve wanted plain html hosting for a while, but made do with google sites (i.e. crappy but free). I’d also wanted to be able to use the wolfram CDF plugin on my blog, but also not enough to pay for it. However, once I tried mathjax-latex, I was sold. Compared to wp-latex, this “new way” completely kicks ass, and should save me a lot of time.

I tried out an amazon EC2 bitnami image for a while (amazon offers a free trial year to evaluate their offerings). That’s a flexible setup and offers direct access to the Linux VM, which is very nice. However, with an amazon EC2 image, I’m not really sure what I would end up paying. The charts seem somewhat vague, depending on future usage of both machine and storage. I would also have pay separately for a domain name, and pay separately for amazon hosting of the DNS entry.

I ended up deciding to use a go-daddy hosted wordpress instance, which is a flat rate service. It is less flexible than a godaddy standalone web-hosting environment, but also cheaper ($12 for the first year, including the domain name, and ~$50/year after that). It also looks like I can upgrade this to a more generic web hosting environment later if the cost of that seems justified. I’ll see first if only having sftp access to htdocs is enough of a major inconvenience to pay that additional yearly fee. If not, then I may consider changing to another host.

Configuring a custom MathJax configuration was a bit of a pain with only sftp access, mostly because I had to copy the MathJax tree, which was very slow for so many small files. I did that directory tree transfer with FileZilla since sftp ‘put –r’ appears to be busted. This MathJax setup was way easier on the EC2 since the ssh shell allowed for wget and local unzip directly from the apache2 htdocs tree. It’s a shame that the mathjax-latex plugin doesn’t allow the MathJax tree to be served from the default server (what the plugin settings calls the ‘MathJax CDN Service’). Logically, I’d like to be able to use that CDN service, but have my configuration file hosted locally. That config file (config/default.js) is a single small file, and is likely all that I’ll ever have to alter in that whole directory tree.

I haven’t decided whether or not I’ll keep my old peeterjoot.wordpress.com blog, or switch unconditionally to this new peeterjoot.com blog (which will be the new home for any of my mathematical or physics related posts). This new blog has no blog-article content so far, and doesn’t yet have a theme template that I like. What is here so far is:

  • An enumeration of things I have written, including archives of all the individual pdfs that I have posted over the years along with my blog entries. All these pdfs are now stored directly on the new site in the htdocs tree. I will no longer be using any of my (three) old google sites pages as pdf stores.
  • A chronological listing of all the Mathematica notebooks I have written. The newest versions of these notebooks can still be found in my Mathematica github repository. A snapshot of each of these is now also available on the new site, so if you have the CDF plugin installed, these can now be examined by clicking on the links directly. Ironically, with chrome and my CDF installation, I’m able to view the .nb suffixed notebooks directly in the browser, but a click on any CDF (.cdf) notebook triggers a download?
  • I’ve made a couple notes about my setup of the mathjax-latex plugin, and the differences in latex markup with that plugin compared to the wp-latex plugin (which is available by default on wordpress.com). My future mathematical blogging should be way easier, probably won’t require any of my old tex2blog script, and will also look better!
  • An About page, copied directly from the About page on my old blog.

More to come, … now that I’ve finally finished the Stokes theorem chapter in my Geometric Algebra compilation, I expect new posts to be more frequent.