Mary Dickson Diaz

Code, Life, Learning

Tag: rails

the gift and cost of clarity

7-Your Move

An update! Since I decided to Go Into The City many wonderful connections have been made. I updated The Plan with my goals for March:

 

  • Go to coffee 2x+/week, with someone I know and someone I don’t know (find folks doing jobs I want and ask them how they got there)
  • Go to meetups, 2x+/week
  • Find an open source project to contribute to (possibly through Open Seattle, CF App Builder Club or the Outreachy application process)
  • Work through Harvard CS50, Programming Interviews Exposed, and Cracking the Code Interview
  • Apply to jobs, 3+/week
  • Take a new class through Code School or Pluralsight and build a new app or add to an existing one with new skills
    • Angular (focus on Rails backed Angular)
  • Reinforce core skills
  • Stretch Goals:
    • Learn VIM
    • Outreachy application (most likely Wikimedia)

Some of these I am doing well on and others not so much, but we’re not even to the Ides of March yet so I’m just going to silently note it for now. Besides, I think it’s time to narrow my focus even further. Recent conversations have been valuable in determining exactly what type of opportunities I’m looking for among my diverse and varied interests and abilities. This leads me to the following Career Intention:

I am looking for full-time or contract work… 

     …as a junior software developer

     …in a supportive learning community

     …where I can work on substantial projects

     …preferably in Ruby on Rails

     …with people who value diversity and inclusion.

That’s it! It’s a tall order but not impossible to find. And, I need to be putting all my efforts towards learning experiences and projects that will move me closer to this role. Other tech related ventures that are not coding, I bless and release.

The closest match I’ve found so far is an Outreachy learning opportunity with the Wiki Education Foundation’s Wikipedia course dashboard system. The dashboard is built in Ruby on Rails and uses a combination of technologies I’ve worked with and technologies I haven’t worked with but would like to learn. The project manager is based here in Seattle and would be great to work with. The opportunity itself is a three month internship, paid (a small amount), with a respectable network and prestige for alumni that can lead to more opportunities.

I’m struggling to get my development environment set up to jump in and contribute in some small ways (required for the application), but it’s a priority for the March 22 deadline. More to come on the technicalities of that.

It is tough but a great relief to let go of “I’m open to all sorts of tech and coding related opportunities.” It means I’m still not getting paid, but I’m not compromising on activities that won’t move me closer to the goal.

Having now clarified my intentions, it should be easier to share them with the world and let the world help.

how to use the wordpress rest api in rails

Folks, if you’re reading this over at www.marydickson.info, my Rails portfolio site, things are about to get real meta. Several weeks ago I RSVPed for a WordPress Developer’s meetup called Introduction to the REST API. I’ve used APIs with Rails, Angular, and in Twitterbots– an API (application program interface) is simply a way to transfer information from a server to a client, often using a format called JSON (JavaScript object notation). APIs are key to mobile apps that access the same database as a web based site. “REST” (representational state transfer) means that a system understands a set of standard verbs used to communicate over HTML, including: GET, POST, PUT, DELETE, etc. You can use an AJAX (asynchronous JavaScript and xml) call to transmit data via the REST verbs and either fetch data, post new data, update existing data, or delete a record, and the information will be persisted in a database somewhere behind the scenes.

That’s a lot of acronyms. Here have a picture:

how APIs work, sort of

Super! MARY, BUT WHY SHOULD WE CARE?

Long story short: I’ve had this WordPress blog since I started coding, and since then I’ve coded other web sites “from scratch,” including a professional portfolio site, that are much easier for me to customize and that add legitimacy to my claim of web developer. So that is what I want to share with potential employers but I *also* want them to see my awesome technical blog posts so they will think “She sounds cool and writes good. Let’s pay her money in exchange for her time!” UNTIL NOW the way to do that was to direct people to this site, marydickson.com, and hope that they will also go check out marydickson.info, or vice versa. Awkward.

The WordPress API allows me to import blog posts from marydickson.com and render them as a tab on marydickson.info. If you have any sort of non-WordPress site and you’d like to link to or display your blog posts, you can do that with the WordPress REST API. I’ll walk you through what I did to get this working in a Rails app:

Continue reading

try rails 5

Hey folks! Last week wrapped up my second teaching assistant commitment, and while I managed to get myself invited back (barely) (I have more to say about this), I’m taking a break to focus on building skills and job seeking.

On the menu for today: let’s talk Rails 5. This’ll be short, since I need to dive into it.

Screen Shot 2016-02-03 at 3.21.29 PM

yaaaayayyyyayayyay

BUT FIRST… version control.

Since I finished my Ruby on Rails training in 4.something, Rails released a beta version of 5.0, and Ruby has also released a new version, from 2.2 -> 2.3. I’ve fought hard against installing a ruby version manager after disastrous attempts with rvm and rbenv, which hate each other, and will leave your development environment totally FUBAR if you’re not careful. So I nuked everything and avoided any Ruby version control, until now– and now I know better, and there’s no longer any excuse. My instructor says “try chruby!” so chruby it is!

I followed these instructions… including the setup for powder, which is my Rails development server of choice. I installed Ruby 2.3.0 as default and 2.2.4 as a “so then we’ll have it”. Apparently I had been using a version of ruby called 2.2.3p173.  Gross. No more!:

(Oh right, I have to update to El Capital also. Dammit.)

OK, ONTO RAILS:

So now we have software version control, sweeeeet. However, that version control does not extend to Rails, so how to play with the new version without destroying my current install (most recent stable version)?

Option 1: Clone the Rails repo and create a new Rails app from that starting point. 

I followed this guide for how to clone the Rails repo and then create a new Rails API app using the latest beta version (“edge”):

Fun! This worked as expected. I did have to run a bundle install before the bundle exec rails new etc would work. If you go this route, at the end your gemfile will contain this line:

gem 'rails', github: "rails/rails"

Option 2: Create a Rails app like normal and then update the gemfile with desired Rails version

Do you really have to clone the entire Rails repo? Probably not, right? In my second attempt, I tried to teach an existing Rails app to use the new version. The latest beta release in rubygems.org has this language for your gemfile:

gem 'rails', '~> 5.0', '>= 5.0.0.beta2'

However, that did not work. This did!

gem 'rails', '5.0.0.beta2'

I had to run a bundle update after bundle install, but otherwise everything went smoothly.

COOL NOW WHAT?

Well, my install worked a bit TOO well, and now all new Rails apps are initiating with 5.0. That was not my intention, but it should be easy enough to switch back if needed. Funny enough, when I run a new Rails app now, this is what the gemfile looks like:

gem 'rails', '>= 5.0.0.beta2', '< 5.1'

YMMV. Gentle reminder: Rails 5 is not currently recommended for production environments.

the elephant on your desktop

(No, not that elephant.)

This elephant:

At some point in the last few weeks, I added this card to my Trello task-tracker:

All new Rails apps in postgres

And then I did nothing about it until I was trying to do something else and couldn’t get a program to load because of, oh yeah, postgres. Time to deal with that, I guess!

There are three popular options for running a Structured Query Language (SQL)based database on Rails: MySQL (owned by Oracle), sqlite3 (comes built-in with new Rails apps), and PostgresQL… the one with the elephant that’s OK to run on Heroku.

I’ve been using the Rails built-in database mostly, switching over to Postgres for production on Heroku, but it’s a best practice to use the same database for your testing, development and production environments. I can’t really speak to the differences between the three except that my perception is that MySQL is widely hated and Postgres always takes some flailing around on my part to get it to start.

$ rake db:create
$ rake db:migrate
$ rake db:reset
$ rake db:hello_is_anyone_listening

So I was excited to take on a project refactor this week built on Mongo DB, a no-SQL database. Rather than using Active Record and data migrations (hello, hello, is this thing on), Mongo stores database table information directly in the model records where they’re easy to add, delete, or change.

Hooray no migrations! Hooray another tool in my toolchest!

That bit of learning curve did not last long as we realized that what we want to build requires relational associations that a SQL-less database isn’t optimized to handle. I felt a bit sad about not getting to play with a new toy until I ran into this:

Screen Shot 2015-10-19 at 9.34.06 PM

I’ve run into this “master-slave” business before in software and my response was a big “wtf” followed by an “I’m not using this.” And so far, I haven’t had to, since there have thus far been alternatives.

So over to Postgres we go! Commere you big lovable elephant. Give mama a slobber. I shall add to my box of tricks “converted an app from a no-SQL database to Postgres” and all shall be well.

  • Here is a great (long) article by a programmer I admire titled Why you should never use Mongo DB.  This is the type of technical writing to which I aspire.
  • A cloud data storage option I am really excited about: The Art Guys Heads in a Cloud Data Storage Memory Services (I miss you, Houston!)
  • Ok FINE here is A Young Woman’s Etiquette Guide to Coding but I have to say I am annoyed to the point of dismissal that Black Girls Code (a great organization) is listed here with the byline “powered by American Express.” Probably the author meant to say “powerful black girls and women.” Yes, that’s more like it. That downer aside, some good information here.

try angular

this is what angular feels like, a bit

In the last two weeks of my Code Fellows Ruby on Rails bootcamp, we’re focusing on JavaScript, JQuery, and all their friends. This week we kick off with Angular. Angular is a JavaScript tool created by Google for fast, responsive websites. I completed the (free) Code School course “Shaping Up With Angular” and I’m about to embark on a quest to connect it to a persistent database. In my case it will be a Ruby on Rails app.

But first, let’s talk Angular!

MODULE

When you create a JavaScript file to hold some Angular, you initialize it like so:

var app = angular.module('gemStore', ['store-products']);

if you’re not well-versed in JavaScript, this is essentially saying: Declare a variable “app” and set it equal to an Angular module named “gemStore” that depends on another module named “store-products.” Once you’ve declared at least one module, you can get going filling it up with useful stuff like…

CONTROLLERS & DIRECTIVES

Controllers work similar to how they work in Rails. You can set up and assign a controller to a specific part of your webpage, and it can render and manipulate data in a variety of ways. In the tutorial, we set up controllers to manage information about the gems, the product tabs, product reviews, etc. If your code is getting repetitive and/or you want to isolate specific chunks of the page, you can create directives instead that will load a separate html page using naming-conventions (much like how Rails renders partials). Depending on what you’re trying to do, you may be able to include controller functions in a new directive and eliminate the need for a separate controller altogether. Neat!

SCOPE

Angular controllers are called on specific DOM elements , and operate within the scope of that element only. So for example, here’s some pseudocode:

<section id=gems ng-controller="gemController">
  <unordered list of gems>
    <gem 1>
    <gem 2>
    <gem 3>
  <end of list>
<end of section>

Outside this lovely, contained section, if you want information about gems you are entirely out of luck. Note how any of the list objects know about gems (and any child elements we might create under them, if we so choose)–basically anything that’s in the gem section family.

But not outside that family. They know about other stuff, maybe. Like maybe they know about…

DATA BINDING

If you’ve ever typed on a website and had text show up magically elsewhere, tracking as you type, that’s a two-way data-binding and Angular is a pro at it. Here, why don’t you go make some boxes to see how it works? Hmmmm… boxes. That’s not very try angular. Get it, triangular? I feel like this demo could be improved… perhaps a project for a rainy day…

DEPENDENCY INJECTION

Wow, that one sounds pretty grim, right? Coffee is my dependency injection these days. But we already saw this above — you remember in that top example how my app.js had an array of one element — it looked like this:

angular.module('gemStore', ['store-products']);

The app can’t run without the file where I’ve created a module named ‘store-products’, so injecting the dependency here tells my app where to look to import that info. Once it knows how to read ‘store-products’, it inherits any and all controllers and directives in that dependency JavaScript file, and the app can load as usual. Quickly, we hope!

Ok, off I go to attach this gemstore to a database… wish me luck and above-average retention as we dive into the last week of instruction (#justkeepswimming).

evolution of forms of governance in a rails app

No, this isn’t a history lesson. It’s an observation about the governing political ideologies that a Rails app takes on over time. Witness:

At Birth: Libertarian 

A basic Rails app has some sort of landing page and usually a database with CRUD (create, read, update, destroy) functionality. Without authentication or authorization, any viewer can initiate any of those functions. Visitors have autonomy to navigate and manipulate the site according to individual judgement, which is why I consider this a libertarian state. An example is something like my Robot app, which, who knows what it will look like at any given point. You’ll all been very polite in not destroying all the robots (you’ve probably been tempted, though). In theory, you can edit other people’s robots and add or delete as many as you want. I still get to determine what data gets collected on the robots, which I suppose makes this a minarchy as opposed to anarchy (users can’t alter the database or page itself). Although, if the chief role of minarchism is to protect citizens against theft, this certainly won’t do that. Quite the opposite. I can’t protect your robots, people.

Soon-thereafter: Dictatorship 

It only takes one “poop” post for the app creator to realize that people on the internet can’t be trusted, and some sort of filters are needed. The most basic filter, where most beginning programmers will start, is Admin v. Everyone Else. Using a gem called “devise” (or something similar), Rails developers can add Users, which thus enables user roles. With users enabled and a minimal amount of programing, an app can be set such that an admin user can login and create, edit, and destroy content, and everyone else can read it. This is how my WordPress site is set up: there’s a login link, but it’s tiny and hidden down at the bottom of the page, because I’m the only one who’s ever logging in. Because I’m a benevolent dictator, you may leave a comment (which has to be approved by me if it’s your first one). This page is “marydickson.com,” so no one is really arguing against my authoritarianism, but maybe you want to invite some friends to create content with you. The “I-have-all-power/you-have-none” model isn’t going to cut it.

One last note on dictatorship: I’ve encountered a handful of webpages that require a log-in before you can see any content. I encountered one this week, in fact, clicking a twitter link enticing advertised as “Things I Wish Someone Had Told Me When I Was Learning How to Code.” Notice there is no link, because when I tried to click through I was redirected to a multiple-page application to apply to be an approved reader. That’s totally their prerogative, but I wasn’t up for that at 7am in bed lazy-clicking my way through twitter, and ps I’m unfollowing you.

“We’re Gonna Need a Bigger Boat”: Aristocracy

When multiple people get involved in the content creation, participation and/or maintenance of your app, you’ll probably need to have users enabled and the know-how to manipulate policies (in class we used the gem “pundit”). With these, you can set more sophisticated and personalized access for your Rails app visitors. Perhaps you have admin, “authors,” “moderators,” etc. On a smaller scale, I would like for my portfolio site to have comments enabled such that anyone can access and leave a comment, whether logged in or not, and where anonymous comments are held as “pending” until approved. Comment leavers should be able to edit or delete their own comments, but not other people’s. This is where I’m a bit stuck at the moment, with my default being to revert back to dictatorship until I figure it out.

Eventually: Direct Democracy? Something else?

On a more sophisticated app, you may have not only users, but user pages and *preferences* where users have the power to control their own settings about what other users (& maybe even admin!) can CRUD. This seems like it would put more power into the hands of the users, right? More towards a democracy? Ironically, there seems to be a correlation instead between more privacy settings and controls, and the value of the data being collected and ultimately owned by the app. Read this description and tell me it doesn’t perfectly describe a popular site we all hate to love:

Totalitarianism is a political system in which the state holds total control over the society and seeks to control all aspects of public and private life wherever possible.

I use that site, too, but they’ve basically said as much as the above^^.

An alternative is *diaspora, a social network where users explicitly retain ownership of their data (and which I haven’t heard much about since the sad death of creator Ilya Zhitomirskiy a few years back). Today the diaspora foundation operates according to three key philosophies: decentralization, freedom, and privacy.

This seems like a key question for any app creator to consider from the beginning: What principles and philosophies do you want to guide your app creation? What tools and skills do you need in order to integrate them?

reviewing the rails tutorials

so you want to build pizza dot net? try rails!

so you want to build pizza dot net? try Rails!

Hey everyone!  This is my last week as a ‘person of leisure’ before class starts up in full force next Monday.  I received a coursework invitation, and the first assignment is to answer the question: “How was your Rails tutorial?” to which I respond, “…which one?

Before I even saw the question I was considering a run-down on the Rails online tutorials I tried, what I learned, recommended order, and which ones are worth salt. So, here goes! These are roughly ranked in “do this first” order unless otherwise stated.

Michael Hartl – Rails Tutorial

oops my cow is upside down

oops my cow is upside down

Continue reading

rails for robots

Look, I made a thing!

Screen Shot 2015-07-17 at 4.45.53 PM

I took a giant leap this week in my knowledge base, learning and launching my first Rails application. It tracks robots that you would like to build. If you don’t build robots, it has no real practical purpose other than meeting the objectives of the assignment.

For those who don’t know, Rails is… how to describe this. It’s frequently paired with Ruby and it’s a thing you stick your Ruby code into to make it a lot more complicated. Kinda. I still don’t really see the point. It connects your code to a database so you and other people can store things. In theory you could design and run a weblog from a Ruby on Rails app instead of using, say, WordPress (hey that’s not a bad idea). (Except that any entry would probably take 50 hours and like 17 file updates.)

Suffice it to say, I have a lot to learn still about Rails.

But my app works! Go add a robot! This completes the three application assignments, so I’ll tinker this weekend and submit on Monday. I am hoping to gain official acceptance before August 10th, which is the scholarship application deadline.

Some thoughts on Rails:

Continue reading

© 2017 Mary Dickson Diaz

Theme by Anders NorenUp ↑