Tuesday, February 20, 2018

quality interactive tests with Lynx, the server-side browser

Working on a web page test on a server, but can't view the page in a normal web browser? It's easy enough to transfer the HTML to your local computer, or... use a text-mode browser!

The Lynx browser is tiny, fast, and supports a good part of modern web pages. It's a great tool for quickly getting a rough idea of what your page looks like.

Example: my Flask app refuses to handle authentication correctly. So, I write a API test to log in to myserver, capture the response, then write it to a server-side HTML file.  Next I use Lynx to view it so I can see what it's doing!

Here's my Registration test:

def test_post(client):
    "validate page that uses POST"
    rv = client.post('/auth/register', data=dict(
        email='test@example.com',
        username='test',
        password='test',
    ))
    if 1:
        with open('zoot.html', 'w') as pagef:
            pagef.write(rv.data)

Run the test

pytest

Next, use the server-side browser to view my output:

lynx -dump -stdin < zoot.html

Output:

   (BUTTON) Toggle navigation [1]test
     * [2]Home

     * [3]Log In

Register

   Email test@example.com____
   Username test________________
   Password ____________________

   Passwords must match.
   Confirm password ____________________

   This field is required.
   Register

Note the "Passwords must match" bit. Ah, there's my bug. In the POST I'd forgotten to send both the password and validating password2 fields.  Bug fixed, thanks to Lynx!

Wednesday, February 7, 2018

Terraform and iTerm2 FTW

1) install imgcat from iTerm2 page
2) brew install graphviz

Now, when you're working on a complex set of Terraform dependencies, you can display them directly in your terminal!

terraform graph | dot -Tpng | imgcat




(Code from the excellent book Terraform: Up and Running by Yevgeniy Brikman.)

Friday, December 1, 2017

pretty titles (and cats) in your terminal!

A little-known feature of iTerm2 is that you can insert images directly into your (previously text only) terminal!  This can be useful (render calculation as plot directly in terminal) or we can use it for silly purposes.

Cats. Who on the interwebs doesn't love cats?

Setup

brew install imagemagick
copy iTerm2's imgcat script into your path

Test: display built-in image

convert rose: - | imgcat /dev/stdin



Pretty Title

convert -background lightblue -fill blue  -font Tahoma -size 165x70  label:Anthony    z.png && imgcat z.png



Good Job, Bub!

curl -s http://thinga.com/assets/uploads/images/Lil-Bub-pic-02.jpg | imgcat /dev/stdin




Note the "Tahoma" font used above is probably only on macOS.  Choose another font that's installed into ImageMagick.  What fonts are those, you say?  Here you go:

List ImageMagick Fonts (Awk FTW)


$ convert -list font | awk '/Font:/ {print $2} {next}' | pr -4t
AndaleMono   BigCaslonM     Herculanum      TimesNewRomanBI
AppleChancery   BrushScriptI     HoeflerTextOrname TimesNewRomanI
AppleMyungjo   Chalkduster     Impact       Trebuchet
Arial   ComicSans     InaiMathi       TrebuchetMSB
ArialB   ComicSansMSB     Kokonor       TrebuchetMSBI
ArialBI   CourierNew     Krungthep       TrebuchetMSI
ArialBk   CourierNewB     MicrosoftSansSeri Verdana
ArialI   CourierNewBI     PlantagenetCherok VerdanaB
ArialNarrow   CourierNewI     Sathu       VerdanaBI
ArialNarrowB   GB18030Bitmap     Silom       VerdanaI
ArialNarrowBI   Georgia     Skia       Webdings
ArialNarrowI   GeorgiaB     Tahoma       Wingdings
ArialRoundedB   GeorgiaBI     TahomaB       Wingdings2
ArialUnicode   GeorgiaI     TimesNewRoman     Wingdings3
Ayuthaya   Gurmukhi     TimesNewRomanB    Zapfino

Wednesday, November 29, 2017

Wednesday, November 22, 2017

website without pain

Want to put a webapp on your code, but don't care about HTML-CSS-JS? Anvil looks really amazing. You can build a "hello world" form with user registration and two linked Postgres data tables in 6 minutes!! Anvil hello world demo

For my recent wedding I worked building my own site for a while, then built a much better version using Google Forms in 20 minutes, ftw.

Wednesday, October 18, 2017

Appearances in October

Hi all! I love helping people.  For this month I'll be at these locations:

- 10/18: Mentorship Night with Girl Develop It LA!

This event helps intro developers gain confidence and industry knowledge, so they can make awesome stuff and/or get jobs.  I've had great fun volunteering for Girl Develop It the last two years, and am curious about extending my time to the Learn Teach Code group.

- 10/24: October meetup at Coding Dojo in Burbank

I've been attending to and speaking at the Socal Python group for years. As of this year I'm also coordinating. The people are so friendly and open! It's fun just to hang out with such easy and mellow people month after month, even when discussing esoteric technical topics.

This month one talk is on Bokeh, a cool Python visualization framework. This is great for the Data Science people, as Python is the dominant platform, so a graphical package is very helpful.  And, one of my projects Shotglass is using Bokeh in a modest way, to visually understand large collections of source code.

I hope to see you there, at Burbank and Culver City!

Friday, September 15, 2017

NPM package tip

FYI the only way to install and save Node/Javascript libraries is like this:

npm install mongoose@"~4.0.8" --save

This installs anything 4.0.x — major and minor are respected.  The option “@4.0.8” would be only 4.0.8, which is fine, but probably too picky.  The default “^4.0" is terrible and will install anything with major version 4. Don’t ever do this.  It’s also the default. Programmer emptor.

For Python, I generally do "pip install package" to install the latest version of a module, then "pip freeze mypackage >> requirements.txt" to capture the exact version number.