Using Emacs - 12 - Flycheck, Jedi, Python

This week, we're going to look at my setup for Python programming.

I'm an educator, not a professional developer so I'm not working in huge code bases with dozens or more files at a time. I do periodically work in medium size code bases and will talk about cross file navigation and project management later on. There are also more powerful emacs Python packages. One being elpy. Elpy looks pretty cool but for me, it's overkill.

Today's about the basics.

The first tool I show is flycheck. It does code checking on the fly and supports tons of languages. You might have to install some external checkers though. For instance, I installed pylint for python syntax checking with:

sudo pip install pylint

Cofiguring flycheck is as easy as:

(use-package flycheck
  :ensure t
  :init
  (global-flycheck-mode t))

The video all shows how I like to run Python from within emacs.

The other tool I use is Jedi. It provides more extensive completion for Python.

Here's the setup:

(use-package jedi
  :ensure t
  :init
  (add-hook 'python-mode-hook 'jedi:setup)
  (add-hook 'python-mode-hook 'jedi:ac-setup))

The last hook sets up the autocomplete.

For jedi to work, you'll need to install the jedi server which is done in emacs by running M-x jedi:install-server. For that to work, though, you'll need to have Python Virtualenv istalled. I did that with:

EDIT: I just got a report that you might need to also install epc (sudo pip install epc).

sudo pip install virtualenv

Here's the video:

Relevant links:

Ed Disruption - why it's different

Earlier today I read this post by Eliot Horowitz, founder and CTO of MongoDB.

Eliot titled the post "Innovate vs Appropriate" and talks about the importance of knowing when to come up with something new vs when to use the accepted tool, technique, or method. Eliot, of course is discussing this as it applies to MongoDB and it's well worth a read but it got me thinking about the ever popular need to "disrupt" education.

I've witnessed this disruption or Ed Reform for the last decade plus. The basic notion that public education isn't working so we need to disrupt things. We've suffered through:

  • Vouchers
  • Charters
  • Online "learning" replacing teachers
  • Teach for America and other temp type efforts
  • Merit pay
  • VAM for teacher evaluation
  • and more

These disruptions are brought to you by your friendly neighborhood billionaire "philanthropist" or your politicians.

By and large, they haven't worked.

Bill Gates got us to close down community schools and create small ones. While we did need more small schools, overall it didn't work (link, link). VAM teacher evaluation is arbitrary and capricious, merit pay has never worked, nor does the online thing. Meanwhile, charter schools by and large don't do better than public schools.

Rather than saving our schools, these efforts have lowered teacher morale and done little for our most vulnerable children.

So, what's the difference between ed disruption and the tech world? Well, for starters, those disrupting education totally ignore the very advice that Eliot posted about today.

Disruption to and of our public schools hasn't been a matter appropriating what works and innovating what needs to be innovated but rather a playground for pet projects of politicians and well meaning rich folk. Rather than looking at something simple that works, like, say, smaller class sizes, we get computerized testing. Instead of experienced teachers, we get inexperienced newbies that leave after their commitment is up.

Why the difference? It hit me while reading Eliot's post. When a founder is "disrupting" he has skin in the game - it's his company - sink or swim. Not so for education reformers. Politicians merely need to be re-elected.Sso as long as something looks good short term, it is good. Those who disrupt schools are never held accountable. We got small schools and VAM from among other places, Bill Gates. He admitted his reforms didn't work but was there any penalty for disrupting so many lives? Nope. For politicians, it's the same story. As Mayor Mike Bloomberg once said "If they don't like my education policy, they can boo me at parades."

Can we fix this? Sure, but not unless those forcing the changes have real skin in the game. Will it happen? I'm not holding my breath.

Using Emacs - 11 - Reveal.js presentations

Happy to be back after a couple of weeks.

My wife and son spent some time in San Francisco, Mountain View, and Seattle. The main reason was to see our daughter who's interning out there for the summer but it was also a great opportunity to catch up with over 100 former students. If you're interested in seeing more, I wrote a bit about it here.

I was originally going to start talking about Python development but then saw this post on reddit about reveal.js and using it with org-mode. Since reveal.js with org-mode is my goto presentation tool I thought I'd do a video on that before getting back to "your regularly schedueld program."

The main package you have to use for reveal.js presentations in org-mode is org-reveal. The package to install is ox-reveal. I also installed htmlize for syntax highlighting. Here's the code from our configuration file:

(use-package ox-reveal
:ensure ox-reveal)

(setq org-reveal-root "http://cdn.jsdelivr.net/reveal.js/3.0.0/")
(setq org-reveal-mathjax t)

(use-package htmlize
:ensure t)

The org-reveal-root setq tells your presentation where to find the reveal.js code. In this example, we're getting from the cloud. You can also install it locally.

The org-reveal-mathjax is just so that LaTeX equations will look nice.

I'm hoping the video is pretty self-explanitory and the org-reveal home page is pretty thorough but since the documentation is lagging a bit behind the code and due to some versioning issues, here are a couple of things to watch out for:

  • I made a samples folder where I'll put code for this series that isn't part of the configurations.
  • I showed :frag (roll-in) as an example of revealing list items one at a time. Those parens are important and are needed but weren't in earlier versions - this took me far too long to figure out.
  • If you read the docs you'll see that there are many more transitions and you can mix and match them on a page.
  • You might have to upgrade your emacs packages. If you list-packages in eamcs it will tell you if you have packages to upgrade. You mark them for upgrading by typing U and then do the upgrade with x. If this doesn't work, you can try getting rid fo the elpa folder and then re-installing.
  • The mazelesson sample presentation shows more features, many that we haven't covered yet. Check it out but remember that it's for an earlier version of org-reveal.
  • Github pages and rawgit are cool.

Hope you enjoy this. Please add any reveal.js tips and tricks of your own.

Relevant links:

West coast trip - a nice close to act I

facebook.jpg

If I look at my leaving Stuyvesant and the NYC Department of Education to join Hunter College as the end of Act I of my teaching career, then our family's West Coast swing was a nice way to pull down the curtain.

The impetus for the trip was visiting Batya - she's interning at Facebook this summer and having an absolute blast.

The plan was to spend a few days in San Francisco, then a little south to Mountain View, where Batya was staying, and then fly up to Seattle for a couple of days.

Of course, while out there, why not see if some of the StuyCS family wanted to get together.

I knew I had a lot of former students out on the West Coast but still, I was overwhelmed and humbled by the number of people who wanted to spend time and catch up.

We kicked things off at Bloomberg Beta thanks to Roy Bahat. Roy was never actually my student but we've gotten to know each other over the years and I value him as a friend and advisor. Roy provided the food and the space and about 60 former students + a few old timers showed.

bloomberg.jpg

A couple of days later, we had a lunch meetup for the Googlers:

google.jpg

and a happy hour at Facebook (sorry, no picture). Then in Seattle, a nice dinner to close things out.

seattle.jpg

Between these events there were some lunches, a barbecue at Batya's place and even a drive by visit with a former student at Microsoft. Overall, it was easily over 100 students over the course of the week or so we were out there.

I've often said that one of the things I'm proudest of is helping to build the StuyCS family. A community of people spanning decades. Over the week, we had events mixing students from the mid 90's to youngsters currently in college and on their internships.

Seeing all these people meeting and supporting each other gave me a "proud pappa" type feeling even though I didn't do any more than set the stage for them getting together.

Over the week, the conversations were also great - not the straight tech ones, but the ones that really made me proud of the crew. From Seth talking about how to better get good CS Ed to more kids, to PJ discussing why he feels it's so important to be an active mentor to his young programmers and how to get them to be real thinkers, to Mike, Sam, Kathy, and Leo discussing the disconnect between privileged families and those struggling to get by.

What more could a teacher want than their former students being both happy in their lives and careers as well as good people seeking to make the world better for everyone.

The only thing that made me sad about the trip is that with all the big events, I really didn't get a chance to spend the time I wanted with everyone. I hope to do better next time.

So, I've now been at Hunter for one semester and things will really ramp up in the Fall. I'm still a proud part of our StuyCS family and if being a part of pulling it together is the legacy I left, I can live with that.

The trip was a nice symbolic way to lower the curtain on act 1. I'm counting on the StuyCS family and all the other players to help so that we can make sure act 2 is a success and we can build something similar for more young people throughout the city and perhaps the country.

Using Emacs - 10 - org init files

I'll be traveling for the next couple of weeks so I probably won't have time for another video until mid to late July. I'll probably write a post about this series and do some regular blogging over that time but probably no new videos for a couple of weeks.

Also, a couple of notes about the series:

  1. Instead of making a separate git branch for each episode, I'm just adding on to the master branch on GitHub. If you're not familiar with Git and GitHub don't worry about this. Hardly anyone will notice a difference.
  2. If this theme doesn't show well on video, please let me know, I'll change it.

Ok, now to this installments video.

It talks about using org-mode to store our emacs init file.

The first key is that you can put code-blocks in org-mode:

#+BEGIN_SRC emacs-lisp
(emacs-lisp code goes here)
(more emacs lisp goes here)
(and you can have even more here)
#+END_SRC

Since it's elisp you can run the individual line using the usual C-x C-e but you can run the entire block by placing your cursor anywhere in the block and typing C-c C-c.

One minor annoyance about editing code blocks is that it doesn't do syntax highlighting or auto indentation. To solve this, emacs lets you pull up an editing buffer by typing C-c '.

You're supposed to be able to save your changes with C-c ' again or C-x C-s and kill the buffer without saving changes with C-x C-k but the version of org-mode that came with my version of emacs didn't support it - I had to install a newer version of org-mode from melpa.

I couldn't figure out how to do this via use-package, but if this problem happens to you, you can just type Alt-x package-install and then type org and hit enter to install it.

Once you do that, you might have to reload emacs but then everything should work.

This lets us move most of our configuration to a separate file. We're calling it myinit.org and storing it in our .emacs.d directory. You can use any name except init.org as I mentioned in the video.

The file's a little big so here's a link to it: https://github.com/zamansky/using-emacs/blob/master/myinit.org

Notice how GitHub formats it to look all nice.

Here's the raw file so you can see the gory details: https://raw.githubusercontent.com/zamansky/using-emacs/master/myinit.org

Since we're loading the file in overview mode, when we load it in emacs we see:

* interface tweaks
* try
* which key
* Org mode
* Ace windows for easy window switching
* Swiper / Ivy / Counsel
* Avy - navigate by searching for a letter on the screen and jumping to it
* Autocomplete
* Themes

We can tab open and close each section and add text to clarify things around the code blocks.

All that's left in init.el is:

(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives
	     '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

;; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
	(package-refresh-contents)
	(package-install 'use-package))

(org-babel-load-file (expand-file-name "~/.emacs.d/myinit.org"))

With the last line performing the magic of loading our org file and running all the code blocks.

Finally, we added a couple of small interface changes:

(fset 'yes-or-no-p 'y-or-n-p)
(global-set-key (kbd "<f5>") 'revert-buffer)

The first line lets us type y or n instead of yes or no and the second let's us reload a file into our current buffer using the f5 key.

I hope you enjoy this video and find it useful:

Relevant links:

Hillary and Student Loans

Yesterday I read over Hillary's briefing on her initiative on Technology and Innovation.

A lot of it sounds good but, at least for the education piece, I have my doubts. My feeling is that she's pretty much aligned with the current administration education wise and the current administration has been as bad if not worse than the previous with respect to public education.

While I have issues with some of the education pieces and very much like some of the others, I don't want to get into that today. I want to focus on one specific part of her plan. The part that defers college debt for up to 3 years for founders and entrepreneurs. This sounds great but is this really a good thing?

Some initial responses from the education community is "what about young teachers, don't they deserve some help on college debt? What about nurses?…" and of course they're right. On the other hand, I don't want people to go into teaching for 2 or 3 years just to get some debt relief benefit and then jump ship. That's the Teach for America model that I feel has become so harmful.

But again, that's not where I'm going with this.

Let's start with "who are these founders?" I don't have any hard data but I have read a couple of recent pieces that indicate that founders right out of college are typically from well to do backgrounds. This of course makes sense. A kid up to his or her eyes in debt from a poor background. No savings, no property, likely a family, that is siblings and parents who are also treading water can ill afford to take a big financial risk. A kid from a monied family? Much more so.

This alone makes Hillary's plan a boon for the wealthy but not so much for the people we need to give a hand up.

Next, this plan talks about the founders and only says it will "explore similar incentives" for early employees, citing "10 to 20." This doesn't seem right to me.

Now let's look further into the benefits. I don't know what the success and failure rates are for startups. I've seen a bunch of figures including:

  • 90% of startups fail within the first three years
  • Three out of four startups fail
  • Of 10 startups, 3 or 4 totally fail, 3 or 4 break even and the others turn a profit.

I don't know where the truth lies but I'd imagine that the success rate for startup by a recent college graduate, wet behind the ears is probably higher than for a more season professionals.

Hillary's plan defers debt for up to three years. If any of the failure numbers cited above are near correct it means that these kids will have burned through up to three years with the experience of a failed startup to show for it.

I've always advised my students, all things being equal, start at a big or mid size company, develop your chops, learn how they do it, further build out your network, and then go out and do your thing. Most kids are better served not going directly from college to their first startup.

So there it is. A plan that makes for great "press release" but is it really addressing the issues?

On Teaching, Mentors, and Role Models

Yesterday over at AVC Fred blogged about the AFSE graduation and posted a transcript of the speech he gave. It's well worth a read.

Some of the comments touched on mentors and role models so I though I'd talk a little about that here.

I've always believed that as a parent, modeling - that is, how we behave is one of the largest shapers of our kids. It's one thing to take your kid to a museum because that's what you should do as a good parent and another if you think - "I wants to go to that museum and damn it, I'm taking you along." I'm no psychologist but my gut tells me the former is good but the latter is better.

This of course extends to schools. As teachers we deliver instruction but we also communicate through how we behave. Students are very perceptive and we can have influences that we don't even know. I remember a parent who thanked me because their child started exercising and being more active because of me. It's not something I ever talked to the kid about but I would run after my classes at Stuy, ride to school and in class I might give an exercise anecdote or two. Just by doing something healthy and positive where kids can see it led to some good.

Now, as teachers, we have limited reach and just as in many cases where a child won't listen to a parent and needs a friendly teacher to weigh in, there are plenty of times a student won't really listen to a teacher, particularly in CS. Most CS teachers don't have extensive CS backgrounds and self taught kids frequently feel they know more. Even when a student believes that a CS teacher's got the goods, they're skeptical - teaching as a profession has been so beaten up many students will have a ""so why are you teaching and not working at Google" attitude.

Even with the best intentions from parents and teachers, for many students, particularly those from poor backgrounds there are limits to our influence. If a parent has to work multiple jobs at crazy hours, they have less time to be a positive role model. If they've never been to college or worked in a white collar profession they won't have the connections and resources to effectively guide their child through the education to profession maze.

This is where mentors and role models become so important.

For me, I first saw this when I was a young teacher. My graduates hadn't gotten to the real world yet and I hadn't developed a reputation. I'd have friends come in to give tech and industry talks. What I found was that in addition to being inspirational, it help authenticate me as being legit. When they would talk about a best practice that I had already taught them, the classes got the idea that maybe I did know a thing or two about this CS stuff.

You could see the impact when we held "Tech speed dating" events where I mixed current high school students with professionals.

So many comments afterwards like "I didn' know I could do that in CS," "now I know what I want to do…." Slam dunk!!

Of course, you have to curate your volunteers. While a guest talk from a very senior, very established adult can be inspiring some times, they can be so far removed from the kids next steps, it can actually be intimidating and a turn off. As a side note, I don't think that this would be the case at all with respect to Fred's graduation speech. His overall sincerity and the fact that he's so connected to the school and known to the kids made sure of that.

When I made my first Hunter college event, I wanted to kick start and excite the current students and also give myself some CS street cred so I carefully selected the participants for our first panel / mixer. I had:

  • A young VC
  • A mid 30s CTO of a mid size company
  • A mid 30s Facebook engineer who also spent time at Google
  • Assorted recent college grad tech people from big companies, start ups, and everything in between.
  • I tried to have a diverse crowd.

I wanted a couple of more senior people to show the end of the road but I wanted most of the people there to be at "the next rung in the ladder." All indications were that the event was also a slam dunk.

Through all of this it's become pretty apparent to me that bringing in adult mentors and role models can be even more important than covering every little bit of whatever curriculum you're teaching. Some people say that we need more female High School CS teachers and while I agree with that sentiment, I'd rather have the best CS teacher I can get regardless of background as long as I have amazing women in tech to provide for my students as role models.

This led me to think about a couple of the CS Ed programs that I support. TEALS and ScriptEd. I like both, but they're different models. In TEALS the volunteer works with the teacher. In ScriptEd, the volunteer is the teacher. I have many former students that have volunteered through TEALS but I don't know any who've done SciptEd so I don't have the same "inside" info.

For TEALS, those volunteers are also role models. Every day that Etsy engineer is in the classroom those students see and hear from a tech professional. What's more, they see and hear from one who's taking the time to be with them.

Of course the same is true for ScriptEd but I wonder if after some time the students view the ScriptEd volunteer as the teacher rather than the tech professional.

There's probably some interesting research in there.

Finally nothing is better than really being able to hook kids up with long term mentors. This is something that I think AFSE's been able to do but it's an expensive proposition. It's something I'd love to see more of at schools and as part of the basic budget but with all the money wasted on things like standardized testing and flawed teacher evaluation systems, I don't see it coming any time soon.

Using Emacs - 9 - Themes

Now that we have a nice basic configuration, let's make Emacs look a little nicer.

Like most editors, Emacs can be extensively themed.

As shown in the video, you can quickly see the built in themes using the customize-themes command.

You can load one of these themes by using the load-theme command interactively or, more likely by putting:

(load-theme 'leuven t)

in your init.el. The above code loads the built in leuven theme.

I prefer the zenburn theme. For that, you have to load the zenburn package. Here's the code in our init.el:

(use-package zenburn-theme
  :ensure t
  :config (load-theme 'zenburn t))

In the video, I also mention the color theme package.

So, customize away.

In the links, you'll find some links to some Emacs theme gallery sites to help find something you like.

Thanks for reading and watching and as always, please leave comments, suggestions and favorite themes.

Here's the video:

Relevant links:

Using Emacs - 8 - Autocomplete

Out of the box, Emacs supports various types of completion.

Tab completion for filenames and commands basically work right out of the box and Emacs has built in modes like Abbrev, Hippie Expand, and Dabbrev provide a manner of completion for in buffer text.

I briefly show Dabbrev (Dynamic Abbrevs) in the video and if you're interested in the others, follow the links.

We saw ow the built in Ido mode and third party packages like Ivy, which I prefer, and Helm make for better completions on functions, filenames, and the like and Emacs also has third party packages for in buffer completion.

The two main contenders are auto-complete Mode and company Mode. I use auto-complete, others swear by company. The video shows the basics of auto-complete mode but check both out and decide for yourself.

If you feel strongly about one or the other, please share in the comments.

Here's a basic configuration:

(use-package auto-complete
  :ensure t
  :init
  (progn
    (ac-config-default)
    (global-auto-complete-mode t)
    ))

We'll modify this as move along in the series.

Here's the video:

Relevant links:

Using Emacs - 7- Navigation with Avy

Here's a really cool navigation method that I've been meaning to use more. Avy is a replacement for ace-jump mode which is an implementation of easymotion, a vim plugin.

It's pretty cool and lets you quickly navigate to any spot on the screen.

After triggering avy, or more specifically the avy-goto-char function, emacs prompts you for a single character. When you type it, all instances of the character that start out words change to a highlighted letter. Type the highlighted letter and you jump to that location.

The avy package comes with a bunch of options including a 2 character search variant, a timed variant which drops into search, and more.

The Avy home page has all the details.

Here's the configuration I'm using:

(use-package avy
  :ensure t
  :bind ("M-s" . avy-goto-char))

You can check the avy home page for their recommended configuration which you get by configuring this way instead:

(use-package avy
  :ensure t
  :config
  (avy-setup-default))

Relevant links:




Enter your email address:

Delivered by FeedBurner

Google Analytics Alternative