Mac OS X Dropping Connection Frequently

Quick Fix

Apparently, Mac OSX Mavericks, El Capitan, and Yosemite can experience IP Address conflicts with other computers on the same home network (particularly with Verizon), causing it to drop its connection with annoying frequency. The error message “network cannot be joined” is virtually useless in figuring out how to fix it, as are nearly all mac user forums.

However, I stumbled across a youtube video with the solution. Alas, the creator didn’t speak, and includes no written instructions, so you have to sit through a very slow demo to see what to do. I thought I’d do everyone a favor and write up the steps.

If you’re having this issue, here’s a quick fix to try:

– Open the wifi menu
– Click “Create new network”

In the dialog that opens:

– Choose a channel other than channel 11
– Click “Create”

The dialog closes, returning you to the wifi menu

– Choose your network from the wifi network list

Repeat the above for each mac on the network, using a different channel number for each.

You should now connect to the network, and the annoying network dropping, with it’s ever-so-helpful “network cannot be joined” message should be a part of your past.

Why a channel other than 11? Channel 11 is the default channel that will be set for any computer joining your network. You probably don’t want a new computer or a guest to bring about the return of the annoying network drop.

Slow Fix

This is the long path to fixing it, which works for most people who don’t benefit from the short path.

Kill Verizon DNS Assistance for FiOS Quantum Gateway

The Problem:

If you’ve recently become a Verizon customer, you may find that Verizon has hijacked your browser, so that every time you hit a page that’s not recognized by its DNS servers, you’re redirected to a ridiculous Verizon co-branded yahoo search page.

I guess they still think they need some kind of search presence to be a future-forward internet company – how very 1990s!

This is a wicked nuisance if you’re, say, working from home, and accessing a work server over a VPN. You literally can’t get there. No way, no how.

Verizon helpfully (heh) provides instructions that help you, by pointing your router to a different pair of their DNS servers that shouldn’t cause the hijacking. There’s a reason “shouldn’t” isn’t in plain text …

The Solution:

Tell your router to use public DNS servers, instead of Verizon’s servers.

The following instructions are for the specific router we have, but with a little sleuthing, you should be able to figure out the analogous steps if you have a different router. Your goal is to find and set the primary and secondary DNS servers for your router’s connection to the outside world.

1 – Open a new browser tab

2 – Enter http://192.168.1.1 in the address bar.

3 – Enter your router’s admin user name and password into the login screen (default user is usually admin, password is written on a sticker on the router. BTW – you should change your router’s admin user, following steps provided by Verizon, after you finish this).

4 – Click OK

5 – Click My Network

6 – Click Network Connections

7 – Click the Edit pencil icon for the “Broadband Connection”
If there’s more than one labeled “Broadband Connection,” choose the one with the word “connected” next to it.

(Note: do NOT edit “Network (Home/Office)” – that’s your router’s connection into your home network, leave it as-is).

8 – On the next page, click Settings at the bottom of the screen.

9 – In the page that opens, scroll down to the DNS Server fields.

10 – Choose “Use the following DNS Server Addresses” from the DNS Server dropdown.

11 – Change the DNS addresses to the following:

8.8.4.4 Primary DNS
8.8.8.8 Secondary DNS

(Note: these are google’s free public DNS servers, you can find and use others, or even host your own DNS servers, but these are readily available and don’t spam you with ads when you open a new tab)

12 – Click Apply, to close this page.

13 – Click Apply, to close the next page.

14 – Click Apply, to save your changes.

15 – Click Detect Broadband Connection to restart the router.
You probably don’t have to do this, but it can’t hurt. Once it restarts, you should be connected to Google’s public DNS servers.

Ta Da!!

Now your browser won’t be hijacked by Verizon if you hit a bad URL or try to access servers via VPN.

If you really have your heart set on having new browser tabs hijacked, you can always try ootsi.de. They’ve got a chrome extension, to ensure you get your weather in Scottish: IT’S A STOATIR!

Screen Cap of Names and Genders extracted from Wikipedia

Male vs Female Biographies on Wikipedia

I attended the Boston Girl Geeks Dinner last week, and left with a mission – to extract the names from all the biographies on wikipedia, and analyze them for gender.

There’s a gem that will compare a first name to a 40,000 name dictionary, and determine whether that name is female, male, mostly female, mostly male, or androgynous/unknown.

Wikipedia has an api, but it’s a long, convoluted process to get at just the names of biographical subjects. However, they also have a set of pages that organize biographies according to the quality of the bio. Each of those pages lists … the *names* of the biography subjects. Bingo!

So, I got to learn how to extract xpath data from a page, and do a bit of work to extract exactly what I need from the data (the names are not the only text in the resulting string, so I had to strip the extra content out), then run it through the gender tool.

I’ve made the tool as gentle on wikipedia as possible – there’s no automated running of the whole extraction, each page has to be run separately, by hand, so it won’t create a big load and thus accidentally get my IP address banned. I used a really small page during coding, so the incessant testing would only be grabbing a single page and a few lines of data.

And it works!

Next up: enabling people to edit records, to handle cases where the tool couldn’t identify the gender, and adding statistical analysis.

Fun with FizzBuzz

I decided to make FizzBuzz into something that reads (nominally) like English … because I’m easily amused.

fizz_or_buzz = (1..100)

fizzbuzz = fizz_or_buzz.map do |i|
  not_fizzy = (i % 3 != 0)
  not_buzzy = (i % 5 != 0)
  no_fizz_no_buzz = i.to_s
  when_fizzy = (i % 3)
  when_buzzy = (i % 5)

  if not_fizzy && not_buzzy
    fizziness = [no_fizz_no_buzz]
  else
    fizziness = [ ["Fizz"][when_fizzy], ["Buzz"][when_buzzy] ]
  end

  fizziness.compact.join
end

puts fizzbuzz

There’s a fun little trick in the else clause, taking advantage of ruby’s handling of nil elements in a 2 element array. It’s a *really bad* coding practice, but fun to play with. You can see an explanation of the nil handling here.

screen shot of https://rubygems.org/gems/centering_helper

Rails 4 Gem for Centering Images and Content

When I made the gem for generating column widths last week, it was so I could avoid having to litter my code with divs to center the columns if my database contained fewer columns of data than would fill the screen width.

So, of course, this week, I’ve made a gem so I don’t have to fill my code with divs to center anything!

With the gem installed, you can just put this before the content you want to center:

<%= start_centering %>

and put this after it:

<%= end_centering %>

Resulting in much more readable code:

<%= start_centering %>
  Whatever I want to center.
<%= end_centering %>

Which is soooo much nicer than:

<div class="outer_wrapper">
  <div class="inner_wrapper">
    <div class="element_wrapper">
      Whatever I want to center.
    </div>
  </div>
</div>

Creating it meant learning how to create an “asset gem,” which is easy … if you already know what you’re doing, but can be a bit of a challenge if you’re a noob trying to figure out how to do it for rails 4, which is not covered in the vast, vast majority of internet tutorials and stack overflow posts.

My next post will provide detailed instructions on how to make an asset gem for rails 4. For now, here’s where you can find the gem:

https://rubygems.org/gems/centering_helper

and here are the instructions for using it:

https://github.com/liantics/centering_helper

Screen capture from http://www.rails-dev.com/custom-view-helpers-in-rails-4

Rails 4 View Helpers for Noobs

A view helper is a little piece of reusable code that you can place into your views to reduce the amount of code you have to repeat. You’ve probably already used some, such as form helpers (form_for) or others (image_tag). It’s also possible to make your own. If there’s something you do over, and over again, in multiple views, it’s worth considering making a helper to keep your code DRY and your typing fingers happy.

If you’ve never made a view helper before (or if you were shown how weeks ago, but forgot everything you learned, heh), it can seem a little intimidating. If you’re searching the internet for info, you’ll find lots of info related to older versions of rails, but little related to Rails 4.

Here are a few simple things to remember, and a nice resource that, combined, make it a piece of cake:

  1. The file must be placed in the app/helpers directory, and the file name must end with “_helper.rb”. I made one for centering images:

    app/helpers/centering_helper.rb

  2. The file name and module name must match in the same way controller names and class names match:

    centering_helper.rb
    module CenteringHelper

  3. If you’re including html code in your helper, it needs to be wrapped with the raw method:

    raw('<a href="https://www.lianeallen.com/home/2014/09/view-helpers-for-noobs">Rails 4 View Helpers for Noobs</a>')

    If you don’t wrap it in the raw method, rails is going to treat special characters as if they’re supposed to be text, and will escape them:

    \<, \>, … etc.

    so whatever you enter is going to be printed out as text in the view.

    Unwrapped html as it will appear in your view:

    <a href=”https://www.lianeallen.com/home/2014/09/view-helpers-for-noobs”>Rails 4 View Helpers for Noobs</a>

    Wrapped html as it will appear in your view:

    Rails 4 View Helpers for Noobs

  4. And here’s a nice visual tutorial that will walk you through the simple process of creating and using your new helper:
    http://www.rails-dev.com/custom-view-helpers-in-rails-4

Making My First Ruby Gem

I just published my first ruby “gem.” It’s a “gemified” version of the column width generator module, now available on rubygems.org:

https://rubygems.org/gems/generate-column-widths

And here’s the github page:

https://github.com/liantics/generate-column-widths

A ruby gem is a kind of plugin for ruby apps. You post your gem to a hosting site from which others can get the code, plug it into their app, and use it, without having to completely embed it into their own code (which reduces maintenance hassles for others if you make a change to the gem later).

I did a bunch of looking around yesterday, to figure out how to build a ruby gem. The process is pretty simple. It’s worth a try if you’ve got a chunk of code that solves a problem you think other people are likely also trying to solve.

quickleft has a great writeup, and an associated video, to walk you through the process:

http://quickleft.com/blog/engineering-lunch-series-step-by-step-guide-to-building-your-first-ruby-gem

Screen cap of code snippet

Module to Auto-generate Column Widths in a Grid System

Yesterday, I added the ability for admins to view, create, and edit categories. This meant I needed to display columns of categories, organized by category type (think of it as meta-categories) – just what I had done on the home page, but without the extra column to deal with.

The code I’d written to generate the columns on the home page was seriously ugly, and there was no way I wanted to copy it into *another* controller. Nope. This was a time to stay DRY.

So, I made a module, and refactored the heck out of the code – resulting in what you see above. Instead of more than 30 lines of eeeek!, it’s now 18 lines that you can actually read:

https://github.com/liantics/gph/blob/master/lib/generate_column_widths.rb

Here’s How it Works:

In Bootstrap 3, columns are arranged in rows. Each row has a certain maximum number of columns in it. The default is 12.

The columns in a row can be divided into sections, using a “col-” css class that indicates how many of those 12 columns you want to use for each section of content within the row.

The css class also indicates the smallest screen size on which to apply that class. Any device with a screen below that size will default to using all 12. Everything above that size will use the number you specify. (You can specify for multiple sizes, too, but I’ll leave that to the bootstrap docs).

So, if you want your 12 columns divided evenly into 4 sections, you’d use a span of “3”: which means you want each section take up 3 of the 12 columns. Dividing the 12 columns by the span indicates how many sections you’ll end up with. In this case, 12 / 3 = 4, so the row will be divided into 4 sections.

In your html, the css class to make 4 even columns for all screen sizes, from size small (tablet) on up, would look like this:

col-sm-3

col” = define a column span
sm” = define the screen size at which to start using this span
3” = the number of columns to use for this section.

In a div on your page, it would look like:

<div class="col_sm_3">

So far, so good!

What To Do About Empty Columns?

But what if you won’t know how many columns you’re going to need until you do some other calculation (like in my case, I have no idea if there will be any projects in a given meta-category), and you don’t want to display any empty columns?

The Default Solution is Ugly

The default solution is to pick the maximum number of columns, programmatically don’t show any columns that are empty, and do some css magic to align things. But I don’t like that, because you end up with clumps of unnecessary css alignment divs all over your code. I hate having to add a bunch of nested divs in order to make things align.

What If the Server Could Do It?

I thought what if, instead, the server could figure that stuff out all on its own, and automatically re-size columns based on what’s needed in a given spot at a given time. Even more important, on one page, I needed an extra column of data to co-exist alongside the meta-categories.

So the problem is even bigger than not knowing how many columns I’m going to have, but not necessarily knowing how many I need them to fit alongside. In the case of the home page, from the user’s perspective, the extra column (“projects near the finish line”) is just another meta-category for projects, but from the system’s perspective, it’s something completely different, calculated separately based on the number of donations a project has received, and it needs to fit nicely with the auto-generated category columns.

What I wanted to be able to do from the controller was generate the column span value, based on:

  • The number of new columns I was adding to the view
  • The number of columns that the new columns would have to share space with
  • The minimum span size (the number to divide into the total number of columns)
  • The maximum span size (essentially, this is what to do if there’s only one column)
  • The total number of columns available – in case I decided to use a grid that wasn’t 12 columns wide in the future. I’ve used 9 in the past.

From a code perspective, in the controller, this is roughly what I needed to be able to specify:

@column_span = generate_a_span(
  number_of_new_columns,
  total_columns_in_row,
  number_of_existing_columns_if_any,
  minimum_span_size,
  maximum_span_size
)

And in the view, I’d use something like:

<div class="col-sm-<%= @column_span %>">

But …

Specifying All Those Vars Every Time Would Be Annoying

I didn’t want to have to specify every single variable every time. Most of the time, everything but the number of new columns would be entirely optional, because I’d want 4 columns on most pages, and I’m not likely to change the grid size willy-nilly. This meant making all but one variable optional, and defining defaults for the rest.

The result:

def generate_widths(new_columns,
  total_grid_columns: 12,
  existing_columns: 0,
  min_column_span: 3,
  max_column_span: 12
)

In my controller for the home page, I have:

@column_width = Category.new.generate_widths(
  @category_types_count, existing_columns: 1
)

This handles the new columns I’m creating based on the number of category types in use (@category_types_count) as well as the one existing column generated from another source (existing_columns: 1).

Since I’m using the defaults for total grid columns, the minimum column span, and the maximum column span, I don’t have to specify those.

In my controller for the categories display page for admins, I have:

@column_width = Category.new.generate_widths(@category_types.count)

Since I don’t have to accommodate columns generated by other sources, I need only specify the number of new columns I’m adding, thus I can skip the “existing_columns” specification.

In both views, I have:

<div class="col-sm-<%= @column_width %>">

That’s it.

All I had to do was include the module in my category model.

Extra Cool

The extra cool thing: this can be used for any grid system that uses a numeric value in the css class strings in the view.