braindump, playing around with flask / python / vim / bootstrap

So, I didn’t get into 2.72 build-a-lathe-you-can-sledgehammer-on class, which my brain had decided was my last salvation at actually believing I qualify for graduating as a mechanical engineer from MIT in June. I guess I’m just doomed to make shoddily put together things until I get real life experience or something. I guess the example that comes to mind is makerbot v1, but there’s also something to be said for getting something out the door instead of being worried about whether it is Acceptable.

It’s also supposed to snow a lot so school was canceled for today, so I decided to sulk by coding all day. Bletch, take that course 2. Or something. XD; There’s a course, 6.170 (no, not your grandmother’s 6.170, which was toned down into today’s 6.005; this is now software development principles through the view of web app dev apparently) which I might follow along with. It’s taught in ruby this  year, but it was taught in flask last year so there’s some nice material on stellar.

I’m now following this cool step-by-step tutorial,

*** why isn’t this a one-step process. oh holy robots f*** this is a crappy state of affairs that this takes me several hours to set up properly.


Starting over.

1) make pretty bash terminal (with colors).

in ~/.bashrc,  comment out #force_color_prompt
then in ~/.bash_profile, add the line:
source ~/.bashrc

2) make pretty vi.
I chose not to use the script *shudders* It’s hard to undo and puts an insanely long .vimrc that I can’t understand onto my computer. So I followed the instructions

1. make ~/.vim directory
2. download pathogen, I kept forgetting to do this
3. add a gazillion plugins with git submodule add, as directed

3) ugh escape key = caps lock

4) backup dotfiles on github

…except, I just want that .vimrc file, so yea. I should stop using install scripts I don’t read through. *sigh*

5) update minibufexp

instead of bundle/minibufexpl


Sometimes window arrangement gets messed up, so use
:vertical resize 20 
to get unmaximized tree explorer back.

Now, back to flask

~ note: python doesn’t work; have to do ./ (?).

part V
If you try to run this code, there are import errors

ImportError: No module named openid

Appparently since Grinberg wrote his post, the pip install flask version is >= 0.8, so the syntax is now from 

from flask.ext.login import LoginManager

instead of 

from flaskext.login import LoginManager

See (I arrived there from this post

resetting from zip file

Mm. At this point, I just downloaded the microblog-0.5 zip file, unzipped, did the whole virtualenv / pip install flask ordeal, ran ./ and ./, and everything is now dandy.

part VI.

I didn’t have an image for my email address (well, I’d used plus addressing when signing up for Gravatar but not when signing into the google openID thing, and I didn’t feel like restarting my browser to disassociate myself from the google openID thing). The gravatar took a few seconds to update. To check the code was working, I used

u = Users.from app import db, models
n = users[0]   #In my case, when I print, I get
‘’ + md5( + ‘?d=mm&s=’

This spits out
which worked just fine in the browser, and upon refreshing the app, showed up in the app as well instead of the mystery-man human outline icon.

Well. Now I know why all those silly web-apps make me sign up for gravatar instead of letting me upload pictures. Because it’s easier to use someone else’s service…

Hmm, speaking of which. Adding facebook is surprisingly not so straightforward. Apparently it doesn’t play as nicely with openID (they’re not a provider). Drats, time to make more openIDs.

part vii
I was kind of confused by this part (he explains in more detail later), but keeping the None values works and you can enter whatever into the email address for the admins list.

nrw@ubuntu:~/Dropbox/mblog $ sudo python -m smtpd -n -c DebuggingServer localhost:25
From: no-reply@localhost
Subject: microblog failure
Date: Sat, 09 Feb 2013 15:09:04 -0000

Exception on /edit [POST]
Traceback (most recent call last):
  File “/home/nrw/mblog/flask/local/lib/python2.7/site-packages/flask/”, line 1687, in wsgi_app


IntegrityError: (IntegrityError) column nickname is not unique u’UPDATE user SET nickname=?, about_me=? WHERE = ?’ (u’dup’, u”, 2)
———— END MESSAGE ————

This is pretty nifty! I’m doing the viewing emails in terminal thing. Sorry all you all pine users, but this is a novelty to me.

…okay I get bored and skip to the section I actually care about, the CSS section.

Or more specifically,
Really? That’s all there was to it? The transformation is really nice.

Customizing bootstrap

Final conclusion:

bleah all that, let’s just use the internet.


 holy hexapods, ignore the following, 


because I decided to startover. which involved doing the cd ~/dotfiles, ./ restore, then also doing the ls -la and removing all the remaining symlinks, which looked like
sudo rm .weechat .Xdefaults .xmonad .screenrc .pdbrc .mutt  .msmtprc .inputrc  .hgrc .gimp .fonts .dir_colors

oh robutts what is my life. this is why I’m not course 6.


vim + python

I had an intermediate step where I realized I should probably fix up vi so, y’know, it actually behaves acceptably with python (like recognizing tabs and such).

*blinks* I’m still a bit confused, since I followed the instructions instead of just using the install script. Not actually being course 6, I’m not sure which parts of my ~/.vimrc folder I should put up on a git server (github). *shrug* I can always recreate it now. (I lost my dotfiles after google summer of code ’11 and missed them for a while).

Yuck. Ignore previous paragraph. I can’t get the leader key to work. (What is that leader thing? Turns out maps to by default.)  

 The symptoms look like this. also relevant, following this gal’s example I just reinstall everything.

So, I end up removing my entire .vim folder and reinstall with the sontek install script. Which requires I install ruby first… Whoops, it says rake: command not found.

later: on the leaderkey (set as a comma) not working

…for some reason,

nnoremap : ;

makes the leaderkey not work! wtf ?__? computers.

installing ruby on ubuntu

Conveniently enough, 6.170 sp13 is taught in ruby so I get this link off the slides.

 curl -Sso ./

(I downloaded the non-raw file first by  accident). And following the rest of the instructions, 15 minutes later, after restarting gnome-terminal, I’m set.


rails new helloworld
cd helloworld
rails server

Then I visit and see a “welcome to ruby” page. yay.

Other notes / things I add…

Okay, excellent, now I have lots of things installed on my computer and insanely long dotfiles I don’t understand… Oh well. Some further notes and modifications:

(With following tutorials, as usual, I have to remember to

:set paste

Or else each line I paste in with ctrl-shift-v gets indented.
Apparently the reason is that the terminal can’t tell pasting from a lot of text being typed in at once.)

“Common command line typos
cmap W w
cmap Q q

” Swap ; and :  Convenient.
nnoremap ; :
nnoremap : ; “NOTE: Holy crap this breaks the key. take this line out.

” Spaces are better than a tab character
set expandtab
set smarttab

” Who wants an 8 character tab?  Not me!
set shiftwidth=4
set softtabstop=4

” This is totally awesome – remap jj to escape in insert mode.  You’ll never type jj anyway, so it’s great!
inoremap jj <Esc>
nnoremap JJJJ <Nop>

“{{{ Paste Toggle
let paste_mode = 0 ” 0 = normal, 1 = paste

func! Paste_on_off()
   if g:paste_mode == 0
      set paste
      let g:paste_mode = 1
      set nopaste
      let g:paste_mode = 0

” Paste Mode!  Dang!
<silent> <F12> :call Paste_on_off()
set pastetoggle=<F12>

NOTE: If you are in paste mode, the “jj ” mapping will not work. Also, if you set mouse mode on, you can’t copy-paste out of the terminal. And if you set line numbers on, when you copy-paste the line numbers get copy-pasted too. And on gnome-terminal (or ubuntu?) F10 seems to map to pulling down the toolbar options, so I used F12 instead. I also changed this tab-spaces = 4 instead of 3, because python.

Sontek mentions buffers versus tabs, and last time I only ever used tabs, so I read up on this here:

 set hidden

Oh, and I turn off line numbers and displaying all the whitespace by commenting out the set list and the set number in ~/.vimrc.

other things to read:

So now, some of the shortcuts I can use:
:e  to open a buffer, and ctrl-6 or :b1 to go to whichever buffer is open.
>> and << for indenting
to turn on/off paste mode
😡 to save and close (NOTE! I have, as mentioned, mapped ; to 🙂
:nmap to look at my shortcuts

resetting .bashrc for ubuntu, not mac

Meh, as usual with the internet, the .bashrc on sontek’s site is for mac osx and not ubuntu. I wanted to color my prompt, so I reverted to the default .bashrc
Note that thanks to using the install script, I have a bunch of symlinks and the file I actually want to edit is ~/dotfiles/_bashrc …

and uncommented the “force_color_prompt = yes” line. Then I ran

source ~/.bashrc

to force reload the file and voila! color! yay. See if you don’t know what I’m talking about, although note there are typos in that (e.g. they have color_prompt instead of force_color_prompt)

back to flask / jinja

lol. that took forever and a few inches of snow. It’s now… 1900. and snow’s supposed to get heavy around 9pm. Okay! Time to get going.

/note to self: productive = keep door open and headphones in. otherwise, i feel jittery with the door open for some reason, I close it, and then I fall asleep in an unmotivated heap. =__=;; derp hopefully this too will pass with time. also, being productive feels nice, no matter what particular item i choose to finish on #infiniteprojectlist.

Also, an interesting way to keep track of time passing (usually I use or, set my netbook to go to sleep every 30 minutes and use it to play music while working on my desktop.