Wednesday, December 30, 2015

Python debugging: ipdb

pdb is python's basic debugger.  It's nice because you can use it in a lot of different circumstances and it's independent of any particular IDE.

Here's a nice introduction:

But most often, if I pull out a debugger, what I really want is to play with the objects in a python shell.  pdb has its own shell, but . . . there are a lot of missing features.  In particular, if you want to explore a particular object it's weak because there isn't a tab completion feature.

If you already have ipython, you can use the pdb functionality of pdb in the more powerful ipython shell by using ipdb.

It's simple to install and more than worth it.  Just do

pip install ipdb.

Then, instead of 
'import pdb'

do 
'import ipdb'

and instead of 
pdb.set_trace()

do 
ipdb.set_trace().

You're welcome!


Friday, June 5, 2015

Friday, May 29, 2015

Lots of named tabs--like a scite session but for Gnome Terminal

Open a bunch of bash tabs simultaneously and give them different titles.  Nice!
 
#!/bin/sh 
gnome-terminal \
--tab -t "notes" --working-directory=$HOME/notes  \
--tab -t "puppet" --working-directory=$HOME/puppet \
--tab -t "beamish" --profile=root-beamish           \
--tab -t "odyssey" --profile=odyssey                \
--tab -t "root" --profile=root

Friday, May 22, 2015

More organized javascript

I do a lot of writing in Python and everything seems to be nicely arranged and easy to follow and then I go to what I've written in Javascript and jQuery and it looks like a mess.  It's comparatively hard to follow even much smaller tracts of code.

So here are a couple of resources on organizing Javascript code.
 
http://alistapart.com/article/the-design-of-code-organizing-javascript
http://addyosmani.com/resources/essentialjsdesignpatterns/book/
http://rmurphey.com/blog/2009/10/15/using-objects-to-organize-your-code/

Wednesday, May 20, 2015

Today I learned that properties can't be accessed as functions

It took a long time for me to debug something that was simple.

I had a method defined as a property and I built another method that took its output.

Out of habit, I called the function.  And my operation failed.  The lesson was pretty simple: don't try to call a property.  It's a value now, not a method.

Monday, April 6, 2015

ajax post request: simple

An ajax post request can be as simple as any form in django. Just remember the csrf token!

Thursday, February 19, 2015

leveling up with tail -f: linux live view of error logs

I've been using 'cat' every time I wanted to look at a log view --which was often when I was in the middle of debugging.

You don't have to do that.

http://www.howtogeek.com/howto/ubuntu/a-live-view-of-a-logfile-on-linux/

 instead, just use

tail -f /path/to/thelogfile.log , 


which gives you a live view of your log file.

===============
edit: I've been using this for awhile now and just today I was having issues with wanting to search through the log without leaving the tail -f call.  The solution to that is listed here:

http://www.brianstorti.com/stop-using-tail/

Basically, you can use the same "follow" capability in Unix "less" if you only need to follow one file.

less +F /path/to/thelogfile.log

The cool thing here is that you can use vi navigation and search commands to get around quickly.

Also, it's fairly common that I've been using vim to look at files that I don't want to alter.  It might make more sense to just start out with less.

Saturday, February 14, 2015

Gorgeous vanilla javascript to make a simple Pong using only canvas

I've been thinking about getting into vanilla javascript and specifically into the canvas element.  You can read through tutorials and so on, but nothing is nicer for something like this than seeing good code.  It's even better if it's simple.

So tonight I felt extremely lucky to happen upon this:

Ben Shepherd did a screencast of himself coding up a very simple pong using Javascript canvas here (check out the music on this video too):

https://www.youtube.com/watch?v=ITmH-W49Mvk

But, even better he posted the code.  It's beautiful, with good patterns, and it's extremely easy to understand.  Wow.

Here's the code (and, since this is JS, it's a working Pong):

 http://passion4web.co.uk/ben/pong.html

Friday, February 6, 2015

Django in ipython notebook

Holy moly:

I've been using ipython notebook forever.  And I've been working intensively with django for many moons.  I just didn't know that they two could be married so easily.

Enter django_extensions .

For the details, check out this blog post:

http://opensourcehacker.com/2014/08/13/turbocharge-your-python-prompt-and-django-shell-with-ipython-notebook/

12 factor apps

I was reading through the "django-configuration" documentation and found a reference to a fascinating document that may be worth reading through.  Here's a link:

http://12factor.net/

It seems to be about making maintainable, portable applications.  Yeah, I'm kindof excited about it.

Thursday, February 5, 2015

tool of the day: netstat

Want to know what's going on in your box?  Use netscan.  It will name every port along with the application that uses it.

$ sudo netstat -nlp


Friday, January 30, 2015

Automatic build and reload for Sphinx documentation

I'm beginning to use Sphinx to create a document and I got sick of compiling and reloading every time I wanted to see what was going on. So I learned how to get it to automatically compile to html and then reload Firefox. The solution is below.


It's a combination of two useful tidbits.

One introduces Watchdog:
http://jacobian.org/writing/auto-building-sphinx/

The other introduces xvkbd:
http://stackoverflow.com/a/15589391/456878

A couple of little tricks that make me happy

1.  You can drag and drop a folder onto your terminal to get it's path.  This is shown here on a Mac (from a blog I just read) but I just tested it on my Ubuntu/Unity 14.04 and it worked nicely. 


2. If you want to get back to the directory where you just were, type
$cd -

Finally, one other cool thing: the commands that you use to get around on the command line (CTR-a to go to the beginning, CTR-w to erase the word left of our cursor, etc) work in iPython as well.

Minifying and concatenating js and css

I recently read that browsers are limited with regard to the number of requests that they can make to a single server.  That got me thinking about the CSS and JS that I've been grudgingly adding to Nnums.  Some of those pages are definitely requiring more than their share of web requests.

So this morning I've been looking at various options for minifying and concatenating CSS and JS files for deployment. 

As far as I can tell, this is an area where things have been changing very quickly and where there are many interesting options.  But Grunt seems to be fairly middle-of-the road as far as solutions go.  So here's a link to a sort of "Grunt for Dummies" article:

http://24ways.org/2013/grunt-is-not-weird-and-hard/

Incidentally, this fits my philosophy on learning fairly nicely.  I used to think that rapid learning happened best when you jumped into deep waters quickly.  I jumped into graduate quantum mechanics when I hadn't yet taken undergraduate quantum mechanics, accelerated Latin when I could have taken ordinary Latin, and so on.  I started reading books in Arabic rather than going through all the drills in an undergraduate Arabic class.  That approach can work.  But one of the main things that I've learned is that, while it can work, it isn't the fast way to get on top of a new subject.  The fast way is to start at the very beginning.  And then, yes, gradually push out into those deep waters.  But first get a nice powerful stroke.

Tuesday, January 27, 2015

Habitat for Humanity but for programmers

http://www.freecodecamp.com

Instead of learning to build homes by helping people, you learn to build web applications by helping nonprofits.  Way cool.

Monday, January 26, 2015

Nice set of instructions for speeding up your web pages

Today I was testing my site and I realized that one of the CDNs I was using was hanging.  Not wanting my website to be at the mercy of more failure points than necessary, I brought the hosted jQuery and Bootstrap files in house. 

The result was a surprise: good speed on Chrome but slow on Firefox.

Anyway, I found a nice resource on speeding up a web page with at lot of details that I hadn't learned before:

http://www.sitepoint.com/complete-guide-reducing-page-weight/

One interesting thing is that browsers have a limit for how many web requests they will make to one server at a time.  It's possible that it was this that made the difference between page load times on Firefox and Chrome.  It's a good argument for compiling all your CSS and JS together into one file each per page.


jqueryui and mobile: thanks TouchPunch!

I was pretty proud of my implementation of jqueryui sortable lists.  Then I went to try it on my phone and it failed. 

At first I thought it might be a javascript problem, but thinking about it I realized that the problem is that phones don't have a way to drag and drop using your mouse button.

Anyway, TouchPunch maps touch events to mouse events in a way that makes "sortable" work.  I'm pretty happy with the results.

http://touchpunch.furf.com/

Saturday, January 24, 2015

Unix Tree

You can get a nice directory tree that diagrams your file structure with the command "tree" (it's not installed on Ubuntu 14.04 ls by default--just sudo apt-get install tree.)  It's nice for communicating a layout quickly.

$tree

Focusing on the fundamentals

I've been looking for the next text to go through.  Today I happened on what looks like a nice one, focused on a lot of fundamentals related to what I'm doing right now.  Here's the link:

http://chimera.labs.oreilly.com/books/1234000000754/pr01.html#_outline

Friday, January 23, 2015

Added custom search

It's nice to be in control of the search page.  And it's nice to have the search be exhaustive.  Awesome.

Rosetta-Togetta

I'm working on a fun side-project called "Rosetta-Togetta." 

https://github.com/dhbradshaw/rosetta-togetta

It's an open source collaborative translation website.  For people in the translation or linguistics field, it's a bitext or a parallel-text display where the source language and the target language are displayed together.  The target language snippets are editable while the source language snippets are fixed.

Like a lot of things the project has several purposes.  It's my first project using Go for the back end.  It's also going to differ from other projects in that I want to make a lot of the action happen on a single page and use Javascript to make its behavior pleasant.  So the project is partly about learning those technologies. 

It's also about French.  I speak French fairly fluently--I can read it well and converse in it well.  Thanks to Librivox, I've listened to thousands of pages of French literature over the past few years and have now have ears that are fairly well-tuned for that.  But I haven't had practice writing in the language.  And, since good practice involves feedback, it would be way better if my practising had feedback built in.  So collaborative translation would be way better than solo translation.

Enough about that.  The thing I wanted to mention here is that I found a nice snippet on Stack Overflow for editing text using Javascript.  I'm copying the link so that tomorrow when I want to work on RT I can learn from the link and apply the ideas to the site.

http://jsfiddle.net/BenjaminRH/467S5/

Lite Custom Google Search Alternative for a django site

Right now I have a search bar that is a customized Google search.  It's basically an ordinary Google search whose results are narrowed to only the portions of Nnums that it has indexed.  Since indexing is incomplete and occasional, it's not a great way to search for a bit of data.

Here's a post on a simple way to search the models on your site:

http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap

I think I'll have to try this out.

Monday, January 12, 2015

rust in vim

I'm following through the Rust Programming Language book and I fired up VIM and had only basic syntax highlighting.  What I had to do to fix that was simple once I figured it out:

Copy the contents of the file https://github.com/rust-lang/rust/tree/master/src/etc/vim to ~/.vim .

Tuesday, January 6, 2015

PhantomJS

I'm still on a quest for the best way to have selectors and xpaths that match those from Chrome and Firefox.  As far as I can tell, that means using a web engine.  Right now I'm using Selenium, but it's pretty heavy and I'm looking for something lighter.

PhantomJS may be the thing.

http://phantomjs.org/quick-start.html

http://docs.travis-ci.com/user/gui-and-headless-browsers/


Monday, January 5, 2015

biopython notes

Chapter 1: installation
The main thing to note here is that biopython is not up-to-date for the Ubuntu 14.04.  So if you want the most recent version you have to compile. 

Contribution idea #1: get an up-to-date installer standardized for Ubuntu.

Chapter 2: parsing

from Bio import SeqIO
for seq_record in SeqIO.parse("ls_orchid.fasta", "fasta"):

from Bio import SeqIO
for seq_record in SeqIO.parse("ls_orchid.gbk", "genbank"):

Contribution idea #2: contribute new cases to the cookbook.