Tuesday, January 31, 2023

The Anvil is Gone. Long live the anvil.

I named this blog when I was working through a PhD with a growing family.

I've completed my PhD and had a fun career since then.  My family has continued to grow and now three of the eight children have graduated high school and are off on adventures.  Our fourth graduates this spring, leaving only four at home.

So somehow we made it through the time intensive years with youngsters and did just fine.

But of course there's still an anvil to carry up that mountain -- plenty of goals and expectations and weaknesses to overcome.  But I'll keep moving and I think we'll get where we need to go.

Wednesday, November 27, 2019

The lovely pkill and pgrep

Trouble in Gotham: Guake frozen

This morning my guake terminal froze.  No key combination within guake would work to get it back going, of course, because no keys worked within guake.

So I used ctr-alt-t to open another terminal and top to list open processes.  Perhaps because guake was frozen, it didn't make the top screen.

Enter pkill

Instead, from the other terminal I used pkill.
This killed guake right away.

Thursday, April 6, 2017

ipython magic: effortless module reload

Seeing is huge.  Anything that you can do that lets you see what's happening in a system with more detail or more quickly will help you master that system.  Do you want to understand how your lawn mower works?  Remove the hood.

Python programming can be a pleasure, partly because it's simple to see what you're doing.  If you want to understand a little snippet, you just take it to the interpreter, run it, and get an output.  Edit it and get a new output.

Some effects are trickier to see because they are contextual.  That is, your snippet won't do the same thing if you paste it into the interpreter as it will in the environment where it's meant to live.  This is particularly true for me when I'm working with Django code, which often depends on a Django environment.

The Django shell (./manage.py shell) solves part of this problem.  The Django Extensions shell (./manage.py shell_plus if you've installed the Django Extensions app) can take you further.  But even then if you have code that depends on the actual location of a file, for example, you can't test it in the shell directly.

To get around that issue, I've typically done two different things in the past: 1) run the code in a test and use print statements or ipdb to get the information that I want, or 2) figure out how to reload the interpreter every time I update a module.

This post celebrates the fact that I just learned how to do 2 much more efficiently than before.  So here it is -- effortless ipython reload:


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