vim-padrino
While playing with Padrino this week it didn’t take long for me to start missing rails.vim (Tim Pope you legend!). So I set about looking for a similar script/plugin targeted at Padrino projects. After a quick search, I couldn’t find anything so I cracked open rails.vim to see if I could monkey-patch it into working with Padrino. I’ve since copied rails.vim as padrino.vim and begun working on it as a separate plugin.
Rails and Padrino have similar project structures, so a lot of the functionalily of rails.vim carries over nicely. I began with a few string replaces, and reading up on autoload and the crazy-ass vim scripting syntax. In general the documentation for Vim is very good. Having said that, Tim has some pretty useful and intelligent functionality packed into rails.vim, so the step-up from docs to reading his stuff is significant.
The first change I’ve made is to the Detect method. rails.vim uses this to only enable its commands for a directory that ‘looks like’ a rails project. I’ve modified padrino.vim so that it does the same for padrino projects (line 7):
function! s:Detect(filename)
let fn = substitute(fnamemodify(a:filename,":p"),'\c^file://','','')
let sep = matchstr(fn,'^[^\\/]\{3,\}\zs[\\/]')
if sep != ""
let fn = getcwd().sep.fn
endif
if fn =~ '[\/]config[\/]apps\.rb$'
return s:BufInit(strpart(fn,0,strlen(fn)-22))
endif
...
endfunction
Told you vim scripting was crazy :)
That’s all for now but I’ve put the project up on github where I hope to add to it over time. Here are a few things off the top-of-my-head:
- Recursively search all padrino sub-apps when using commands like Rcontroller
- Keep ‘R’ as the leading character in commands - stay consistent with rails.vim
- Detect Sass and map Rstylesheets to app/stylesheets etc
All these changes should be very do-able given that i’m using the same logic as rails.vim, just a different directory structure.
You can find vim-padrino up on github here, and Tim Pope’s github profile can be found here. Loads of cool stuff!
Padrino Psych::SyntaxError
I recently started experimenting with the Padrino framework and got started using the guides on the project’s homepage. Following along with the sample_blog guide, I ran the admin generator and browsed to /admin. After signing in however, I got the following YAML parsing error?!
DEBUG - [08/Apr/2011 23:30:58] "Account Load (2.4ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = 1 LIMIT 1"
DEBUG - [08/Apr/2011 23:30:58] "Resolving layout /layouts/application"
Psych::SyntaxError - couldn't parse YAML at line 15 column 14:
/home/gerard/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/psych.rb:148:in `parse'
/home/gerard/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
/home/gerard/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/psych.rb:119:in `parse'
…
I downgraded bundler from 1.0.10 to 1.0.9 following some advice found here (my Japanese was a bit rusty but the commands were obvious enough!). And although this fixed the error in Padrino (i.e. I could access the admin area), I could not run a basic bundle command without getting the following error:
gerard@glaptop:~/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.9$ bundle
/home/gerard/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.9/lib/bundler/ui.rb:56:in `<class:UI>':
uninitialized constant Gem::SilentUI (NameError)
from /home/gerard/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.9/lib/bundler/ui.rb:2:in `<module:Bundler>'
…
From here I found the following post on stackoverflow (all hail) which had a similar stacktrace and solution, only for a rails application. The solution is to add the following to config/boot.rb
require 'yaml'
YAML::ENGINE.yamler= 'syck'
The original poster also provided the explanation:
“Bundler [since] 1.0.10 loads Psych as a YAML engine by default. Psych does not work fine with rails (I’m using rails 3.0.4, and v3.0.3 had same issue). See
here. Solution: set another YAML engine explicitly” - coda Feb 25
I assumed the same would be true of Padrino so I upgraded bundler to 1.0.12, edited my config/boot.rb file in Padrino to include the above, and voila! Problem solved.
Seems strange that a fresh install of Padrino would have such glitches with initial configuration. I’ll have to look more into this. Maybe I just need to hit the docs! :)
Git Internals
I recently started reading into the internals of Git and thought I may as well create a post of some sort before I forget it all!
I’ll leave the generic “intro to Git” shpeal out for now and just cut to the chase. Personally, I find that although I use Git for almost everything these days, I rely heavily on a set of high-level commands that just get the job done (most featured here: Everyday Git).
Recently I found a blog post where, in the introduction, Chris Murphy recommends reading a guide entitled “Git from the Bottom Up” by John Wiegley (2008,2009). As the name suggests, “Git from the Bottom Up” is a comprehensive guide on the internals of Git. After checking out the link and reading some of the article I realised just how little I really understood Git, especially the magic going on behind everyday commands like ‘commit’, ‘push/pull’ etc.
It could be argued that developers don’t really need to know a lot of this stuff, but I’m sick of using Google as a crutch when Git throws out one of its scary error messages :)
I’m hoping to do a review of the whole guide starting here with a review (with some extra notes) of the first section of the chapter “Repository: Directory content tracking”
A Git repository in many ways mirrors the structure of a UNIX filesystem.
In UNIX:
- Filesystems begin with a root directory
- The root consists of other directories, most of which have leaf-nodes (i.e files) that have data
- Meta-data about these files is stored both in the directory (file names), and in the i-nodes that reference the contents of those files (size, type, permissions etc)
- Each i-node has a unique system-assigned number that identifies the contents of its related file
- Many directory entries point to the same i-node (i.e. hard-links). It is the i-node that “owns” the contents stored on the filesystem however.
I-node definition: “An i-node is a data structure on a filesystem on Linux and other Unix-like operating systems that stores all the information about a file except its name and its actual data.” (“Inode Definition”. The Linux Information Project. September 15, 2006. http://www.linfo.org/inode.html. Retrieved 2010-01-12.)
In contrast to a UNIX filesystem, a Git repository represents file’s contents in blobs, which are leaf-nodes something similar to a directory called a tree. While an i-node is identified by a uniquely assigned system number, a blob is identified by the SHA-1 hash id of its size and contents. Although this id is arbitrary like an i-node’s number, it verifies that…
- The blob’s contents will never change
- The same contents will be represented by the same blob no matter where they appear. (Across commits, repositories, even across the Internet!)
- If multiple trees reference the same blob, it is just like hard-linking
- As long as one tree references a blob, the blob will stay in the repository
A Git blob and a filesystem’s file:
- A blob stores no meta-data about its contents. All this info is kept by the tree referencing the blob. i.e. One tree could know a blob’s contents as a file created last year called “foo”, and another could know the contents as a file created yesterday called “bar”.
- In a normal filesystem, two files with the same content but different meta-data would always be represented as two files. This is because…
A filesystem is designed to support change, Git is not.
- Data being immutable is what makes all of this work.
- This also allows for more compact storage as blobs are shared across repositories/commits etc
That’s all that I’m commiting (ha!) to memory for now, I’ll be putting more up soon. Here are some links/references:
February 22, 2011 at 9:47am
Using Syntaxhighlighter with Tumblr
#!/usr/bin/ruby -w
def thank(person)
puts "Thank #{person} it works!"
end
thank("Christ")
puts "Loving Syntaxhighlighter with the Midnight Theme!"
To use Alex Gorbatchev’s Syntaxhighlighter, switch to using the plain text editor in Tumblr (Account -> Preferences). If you try to use the default rich-text editor, it (TinyMCE) will add unwanted formatting to any <pre> tags.
I spent a while researching how to get it working (duh) and emailed Tumblr Support in the end. Here’s the response I got:
Hi, Gerard.You may need to use the Plain Text Editor to create or edit advanced post embeds or to control element formatting via HTML. To switch to the Plain Text Editor, click the Account link on the Dashboard and then click Preferences.
I don’t know when this issue will be addresses in the Rich Text Editor. My apologies.
Marc :-)
—
Tumblr Support
support@tumblr.com
Note to self: explore the Tumblr Dashboard!
February 20, 2011 at 7:54pm
First Post
Hi all,
Finally had a stab at setting up a blog! After humming and hawing (spelling) about going with Wordpress or rolling out something from scratch with Rails (for shits and giggles), I decided to go with tumblr and see how it plays out.
I used the article by Jeff. Way on Nettuts to get going with the theme but it turns out the in-built HTML editor was fairly intuitive. So I made a few changes to the background that I had planned to use as a Wordpress theme and uploaded it as a tumblr ‘asset’. After that it was just a matter of tweaking the stylesheet and voila!
Strangely enough, at least for me being a tumblr newb, tumblr doesn’t support comments. I’ve read that Disqus have a JS receipe that’s pretty much plug and play so I’ll investigate that in the near future.