Projects
-
What I Learned at Work Today: Status Code Tricks
At work yesterday, I came across this snippet of code in a Java class meant to handle HTTP responses:
boolean isSuccessful(int statusCode){ return statusCode / 100 == 2; }
My first instinct was to chuckle (and in fact I sent it to a coworker and we both chuckled). What a silly way to test if something equals 200! I figured whoever wrote this years ago was just having a clever laugh at future coders’ expense.
Then today I sent it to another coworker, who pointed out my error, which is that most (all?) typed languages handle integer division by returning an integer.
In Javascript you can just do:
console.log(3/2);
and you’ll see
1.5
displayed on the screen. This is how humans do division, and it’s still how I instinctively think about numbers. But in Java (and Python2, and C, and plenty of other languages), dividing an int by an int produces another int. (This is not intuitive for a lot of people, as evidenced by the cornucopia of posts on sites like Stackoverflow.) That means in the snippet above,statusCode / 100 == 2
would return true for a 200, but also a 204, a 202, or any other 2xx code.Pretty smart!
-
Cool Discovery: Over the Wire's Wargames
I was nerd sniped this weekend by a coworker who told me about Over The Wire’s wargames, which are self-directed cybersecurity challenges. I am just about halfway through the easiest one, Bandit, which in addition to having me scan for open ports and base64 decode strings, is also teaching me quite a few new command-line tricks. Here’s a little random selection:
sshpass
is a fun little utility that lets you enter your ssh password in visible text on the command line. This seems like a terrible idea to use with a production server that you care about, but these games have me storing 30 separate passwords and I want to make sure I’m putting in the right one, and I’m not worried about someone hacking Over the Wire.- Have a weird binary that you don’t know what to do with?
strings
will print any human-readable set of characters that it finds. Useful for playing CTF challenges and probably other things. grep -v thingyoudontwant
will display records that DON’T match the phrase. Thev
stands for invert, clearly.
Off I go to hack into the next level…
-
Get Unblocked Faster: Ask Questions Like a Journalist is now on Youtube!
My talk at Girl Geek X is now available online!
-
Customizing the Command Line for Lazy People
The shell is personal. Why not make it customized to your every whim?
Actually, there are decent reasons not to go crazy customizing things – mainly, the logic goes, if you get too invested in having things a certain way that are ‘not normal’, then when you have to ssh into a remote computer, or god forbid, use someone else’s computer, you get hung up. I get it, but also: 95% of the time I’m using my own computer. I want it to be the way I want it.
Things that I have customized that may be of interest:
- colors
- the default prompt
- the default shell (I love fish, but it isn’t for everyone)
- the default text editor
Colors
You can go pretty crazy with this. Most terminals let you specify the colors in preferences. I don’t usually mess around with this but you can. What I do like, however, is setting colors for
ls
- it helps differentiate between types of files. You can set these manually (cheatsheet here) or use a tool like lscolors, which works on Mac and Linux. I recommend the latter.The default prompt
At the very least you probably want to show your current git branch, which you can do with this arcane command in your config file:
export PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$
Or, I have recently learned, https://bash-prompt-generator.org/ will let you customize to your heart’s content. Probably not everything in here will work for every shell but there doesn’t appear to be anything too crazy in here, it should work for at least bash and zsh.
The default shell
Macs come pre-installed these days with
zsh
, and many people recommend Ohmyzsh to make it work the way it “should”. Windows machines have Powershell. Linux users…get whatever they get? (I have bash, which is just fine with me).This is an unpopular opinion, but having now been using
fish
on my work machine for the past six months, it really is everything a terminal should be.1 The way it shares history across all open windows, the intelligent tab completion, and the way it handles multiline commands are *chefs kiss. If you have never tried a shell other than the one that came bundled with your machine, give a couple others a shot!The default text editor
Look, I will only use vim if forced. (Once you try it, you can’t quit–literally!) If you’re better than me, great, keep using vim. But as this Stackexchange post points out, “I think there are two reasons it’s easy to forget how to exit Vim: developers are often dropped into Vim from a git command or another situation where they didn’t expect to be, and they run into it infrequently enough to forget how they solved it last time.” If you are tired of being “dropped into Vim” you can make it never happen again with:
export EDITOR=nano
in your config file.
Look, I fully admit nano is not a fully featured editor, but when 90% of what I use it for is editing git commit messages and the other 10% is for editing config files, it does the trick, and I never have to remember
:wq
.-
except POSIX compliant, which will be a deal-breaker for many. I get it. It’s a sacrifice I’m willing to make. ↩
-
Hidden Export Options in Google Slides
To publish my slides for Reinforcement Learning for the Math-Phobic I had to do a lot of manual work. I cropped screenshots of the slides (and replaced some text-heavy slides with just text). I turned my speaker notes into complete sentences and interspersed them between the slides. (I was heavily inspired by how Tanya Reilly presents her slides.)
So imagine my surprise when I discovered there’s a hidden feature in Google Slides that can do (some of) this for me!
The menu in Google Slides allows you to choose File->Download->and a variety of formats, including PPTX, PDF, and plain text.
However, if you go to the address bar, there’s one more option.
A GSlides URL looks like this:
https://docs.google.com/presentation/d/{presentation_id}/edit#slide=id.{slide_id}
If you turn that URL into:
https://docs.google.com/presentation/d/{presentation_id}/export/html
then you get an HTML document that contains the slides and speaker notes on one page.
It’s not perfect. The slides are output as HTML instead of images, which as you would expect, does not work well for complicated layouts, some special characters are missing, and slide animations of course are totally gone. But as a starting point, it’s very helpful.
Makes me wonder what other undisclosed options are out there. This Stackexchange post describes a number of hidden commands for Google Docs. Presumably there are a few more for Slides.
And yes, I did try
export/rtf
andexport/markdown
, with no luck. :)