Thursday, October 20, 2016

Blank? in Ruby On Rails

The blank? method (a clever Rails extension for those of us too lazy to figure out what type of object we are testing is) is some very smart code:

[7] pry(#<#>)> nil.blank?
=> true
[8] pry(#<#>)> "".blank?
=> true
[9] pry(#<#>)> [].blank?
=> true
[10] pry(#<#>)> {}.blank?
=> true
[11] pry(#<#>)> find-method blank?
Object
Object#blank?
[12] pry(#<#>)> show-source blank?

From: /home/saracarl/.rvm/gems/ruby-2.2.0-preview2/gems/activesupport-4.1.2/lib/active_support/core_ext/object/blank.rb @ line 16:
Owner: Object
Visibility: public
Number of lines: 3

def blank?
  respond_to?(:empty?) ? !!empty? : !self
end


Let's break it down
respond_to?(:empty?) ?
  if the object has a method called empty?
 !!empty?
  return the results of empty?, "not"-ed twice.  This means if the response to emtpy? is "true" it will return true (!(!true)).  If the response is false it will return false (!(!false))  If the response is "nil" it will return false (!(!nil)).  It covers the case where empty? returns nil instead of true or false -- if the object.empty? is nil, then the object.blank? is false
: !self
Else return !self -- if self is nil, return true, otherwise return false.

Sunday, January 10, 2016

The Theory of Four Things

When you get to a certain tenure in the high tech industry, you've probably worked in a number of programming languages.  My education started with hobbyist BASIC, continued with high school Pascal, and finished with Scheme and C in college.  My professional life until this year included Java, perl, and bash, and I picked up Ruby for fun side projects.  Those transitions and additions happened over years.  In the last 4 months, however, I've done projects in both javascript (node.js) and Python.  That's  a lot to learn in a short period of time, and I'm by no means an expert yet.  However, I've seen enough patterns in modern web programming languages to state the following -- we'll call it The Theory of Four Things:

To be productive in a new web programming language, you only need to understand four things.

Libraries.  


How do to find, install and load the languages libraries; how to reference the library’s methods.

String Manipulation.


How do you print an output message?  How do you take a substring?  (related:  master regular expressions because most modern programming languages use them for string matching.)

Accessing and creating JSON documents.  


Most server-to-server communication is done with JSON documents these days.  Make sure you know how to put things into JSON format and get things out of a JSON object (or as Stack Overflow will probably tell you “a string that just happens to be a JSON object”).

HTTP requests.  


Those aforementioned JSON documents flow via REST API requests, all bundled up into HTTP requests.  Know how to create them, and how to troubleshoot them (this is where knowledge of networks and security comes in useful).

Monday, July 06, 2015

Letter to Camp #2

My 10 year old is away at sleep over camp -- a RenFair camp, since that's what's compelling enough to spend 6 nights away from home if you are the child of two geeks.  Here's the second letter I wrote to her.

Dear J --

I hope you are learning how to defend our castle in case of attack.  It's very important job and you know that your dad and I are too busy writing software to learn the intricacies of archery or jousting.  It's all in your hands.

Similarly, when you return your responsibilities will include the care and maintenance of all of our leatherwork.  That will make my life even more easier than when you learned to clean out the dishwasher!

Have your magic skills increased to the point you can make broccoli disappear, yet?  If that's the case, this camp is worth every cent!  (Heck, I'd even be satisfied if you could only make green beans disappear.)

So there is supposed to be swimming every day at this camp, but there were no swimming pools in renaissance England that I'm aware of.  I assume, therefore, that you are swimming in the moat to the castle.  Do be careful, J.  Those moats often have sea monsters in them imported from the Far East.

I expect that you haven't brushed your hair once since arriving -- don't worry, I think the classic short "page boy" haircuit you'll have after we cut the snarls and tangles out will suit your new knowledge of chivalry very well.

One thing I am looking forward to after your return is increased bravery -- surely taking hot dishes out of the oven will be a piece of cake after blacksmithing!

Love you lots!

Mom


Letter to Camp #1

My 10 year old is away at sleep over camp -- a RenFair camp, since that's what's compelling enough to spend 6 nights away from home if you are the child of two geeks.  Here's the first letter I wrote to her.

Dear J,

I hope you are having a wonderful time at camp.

Things I hope you are enjoying:
meeting new people who think renfair camp is as cool as you do
fighting with swords
living in the forest
bug bites
swimming
sweat
enough food to keep you going
a good night's rest after a busy day
archery
living away from your parents
pretending to live in the 15th century
sleeping in a castle
figuring out just a little bit of life on your own

What we are enjoying without you here:
swim lessons with T
earlier bedtimes
fewer drop offs in the morning
missing you
ice cream
(in other words: you are not  missing much, except for the ice cream!)

Be Brave.  Try something that scares you every day.

Love,

Mom

p.s. I hope you are getting ice cream, too.

Saturday, March 07, 2015

Favorite STEM Books: Psst!




With the help of a young tomboy, a group of zoo animals gather parts to engineer their escape.  Illustrator & writer Adam Rex includes plenty of clever visual jokes that parents appreciate in his intricately designed zooscape.  Both girls like this book -- so it's appropriate for at least ages 4 through 9.

A gift from one of my best friends, who happens to be Ph. D. in Electrical Engineering and work at Google.  She's one of my girls' biggest fans when it comes to achievement in math and science -- when the eldest brought her math grade up from a B (gasp) to an A+, she sent one of the most amazing wooden puzzles for her good work.)


Wednesday, July 09, 2014

Feeding my kids: Breakfast

A friend just asked what I feed my kids for breakfast.  Here's what I told her:

My 3 guidelines are:
1)  vary breakfast/meals as much as possible (we try for 5-7 different meals for breakfast) -- variation hopefully leads to more openness about all food
2)  fruit at every meal (or veg, if I could make that work)
3)  I think everyone's blood sugar is more even with protein at breakfast.
and bonus:  Ben and I take turns which makes #1 easier, but I still have to make #2 happen personally.
reference:  Tavie is 3 and Josie is 9

Example Breakfasts:

  • yogurt "sundaes" -- greek yogurt (sometimes plain, sometimes vanilla) with frozen fruit defrosted to be saucy and a sprinkle of cereal and a drizzle of chocolate syrup
  • steel cut oats -- I parboil these in the microwave the night before and then it's just 5 minutes in the morning.  Josie likes hers with pesto/cheese/bacon bits; Tavie likes hers with chocolate chips (sigh).
  • pancakes made with one of the bob's red mill pancake mixes (make on the weekends and serve leftovers)
  • frozen waffles (kashi or similar)
  • grits -- I buy the frozen "true grits" from HEB (Josie only, Tavie won't eat)
  • cheese toast -- multigrain "good bread" with sharp cheddar melted on top
  • french toast made with good bread and egg substitute (makes it easier/faster)
  • scrambled eggs (Tavie only, sigh)
  • boiled eggs (Tavie only again)
  • peanut butter + banana + honey open faced sandwich (Tavie deconstructs, oh well)
  • apples slices and peanut butter/almond butter
  • refrigerator biscuits (the ones with some whole grain/bran) with bacon
  • muffins (freeze & defrost) -- I can share the whole grain, lower sugar recipes I've found
  • sausage -- either the natural stuff (applegate farms?) or the not-so-good but oh-so-popular lil smokies (turkey)
  • sweet quinoa -- made with half milk/water, stir in chocolate chips

I'm sure there is more, but that's most of our rotation.
I also think it's perfectly reasonable to serve dinner foods for breakfast.  I offer leftovers for breakfast as a way to encourage my kids to stop eating chicken fingers and french fries (sigh) when they are sated, rather that overstuff themself.
And my breakfast ideas pinterest board:  http://www.pinterest.com/saracarl/breakfast/
not all for the girls, but gives some ideas... 

Monday, May 26, 2014

Matagorda, TX Beach Trip

My family loves the beach.  We normally go to Port Aransas, which is a fun beach town, but doesn't have quite the budget-fishing-village vibe of the beach house Ben's family had on Bolivar Penisula before Hurricane Ike swept it away.  After a "coast people" conversation with one of the guys that works at Stuffed Cajun Deli, I asked "so where do you go from Austin for a cheap and easy beach trip?"  His answer:  Matagorda.  So we did our research and made our reservations and this weekend we drove down.

The trip from Austin is about 3 1/2 hours, a full hour less than it takes us to get to Aransas.  It's a tiny town, with about 4 restaurants, 3 gift shoppes, a seafood market and a convenience store with some groceries.  (We picked up supplies in Bay City at a very nice HEB -- but it's 30-40 minutes from the beach.) 

The history is interesting -- Matagorda was settled to protect colonists coming to Stephen F. Austin's original colony, there are historical markers all over town, and we noticed a Episcopal church claiming to be the (Episcopalian) "mother church of Texas."

The geography is also interesting.  Matagorda is where the Colorado River runs into the Gulf of Mexico, so in addition to the ocean and wetlands, there's a lot of river recreation.  We stayed at a beach condo but there were lots of houses lining the river for people with boats and a love of fishing.

The river was actually what saved our trip.  The Texas coast is experiencing a crazy influx of sargasso seaweed on shore right now.  So when we went to the beach, there was 10 yards or more of solid red seaweed two feet high between us and the ocean.  Our neighbors down the beach had brought a shovel and were shovelling a path through the seaweed -- it took them about 40 minutes of work -- but they were kind enough to let our group use it to get to the ocean to swim.  (And the ocean was full of seaweed, too.)  I didn't actually swim, but sat and built sand castles and read magazines in the sun.

[side note:  According to the Texas A&M Galveston Sargassum Early Advisory System:
Public use of these beaches can be severely restricted by the periodic mass landings of the free-floating algae Sargassum, commonly referred to as Seaweed. These Sargassum episodes often occur with little or no warning. They can last for weeks at a time, usually during the prime tourist season.  So I don't hold the seaweed against Matagorda.]

If that had been the sum total of our beach experience, I would have been very disappointed.  (And since this was our first time at Matagorda, we all wondered if it was like this all the time.  Ben even went so far as to ask how long it would take to drive to Port Aransas!  Both of us were worried about the impression our guests and Texas beach newbie friends were getting.) Luckily, the Lower Colorado River Authority had a park right where the river met the ocean that had both sand and no seaweed.  We spent our second morning there and finally had the beach experience we wanted.  (Without waves, but that was OK too.)


We stayed at perhaps the only condo complex at the beach itself -- Bahia de Matagorda #9.  The complex was very nice -- a large pool with a very 1980s swim up bar with in-pool bar stools (and a large sign saying "no glass, no eating or drinking in the pool").  I wouldn't think a pool is a requisite for a beach trip, but our last 4 have had a pool, and it makes coming in from the beach much easier.  You shower off in the outside shower on the way to the pool, then use the pool to cool off after a hot time at the beach.  The pool was actually on an "island" surrounded by a lagoon -- the lagoon added a nice atmosphere, and we saw some another guest kayaking in the lagoon.  (And a big surprise -- the big girls watched a turtle dive into the pool as we got there this morning -- nets were fetched to get it out, but it was an exciting 15 minutes!)

We mostly cooked in the condo, but we did get dinner out one night at Riverbend Restaurant & Tavern.  The large signs warning that the kitchen can take 40+ minutes to get food out once they get busy were a bit disconcerting, but we arrived at 5:15 and had a food in reasonable time.  The food was good for what it was -- fresh, fried seafood.  My french fry aficionado says the fries were boring.  They had fried okra as an appetizer, which was a surprising hit with the kiddos, even if it was just a vehicle for batter, salt, and ranch dressing.

The moms sneaked out to grab fancy coffee at Cattails once we had everyone settled on the beach.  The coffee was a surprise -- good lattes and mochas in a charming gift shoppe/wine bar/coffee bar attached to a surpisingly upscale Karankawa Village Lodge.

I alluding to wanting a "cheap and easy" beach trip, and this one was definitely more affordable than Port Aransas.  We spent $225/night for a 3 bedroom condo that easily accommodated two families.  That's hard to beat!

Will we be back?  I suspect we will, but the seaweed was enough of a damper (ahem!) to color our experience (even though that wasn't unique to Matagorda, but to our trip time) that we may try someplace else before we make it back.