Using Browser Sync with Rails and Local SSL

I’ve always been a fan of LiveReload since I first saw it years ago. However, the rack-livereload gem hasn’t been updated in a long while, and the livereload parent project seems to have died out too. rack-liveload doesn’t support reloading on local HTTPS connections, which was a requirement on a recent project—I needed a new tool.

BrowserSync came to the rescue.

In most cases, using BrowserSync’s proxy mode to reverse proxy a rails app running via a *.dev pow domain works well. For this particular project, there were a couple of specific issues:

Many pages on the project force HTTPS. A common pattern is to disable HTTPS in development: I prefer to keep the development and production delta as small as possible, and keep any HTTPS redirects enabled in production active in development as well. The site used oauth for local user authentication. Each oauth redirect URL needs to be specified in each oauth provider’s admin. This is a pain to manage, and becomes more a pain when a reverse proxy with a unique domain is used sometimes. The SSL certs served by tunnelss were not valid for the BrowserSync server causing browsers to throw invalid certificate errors.

After a bit of digging, I found a way to use my existing *.dev setup with BrowserSync. Here’s how:

Setup Apache + Pow + Tunnelss

Read through this blog post to setup your development environment to serve SSL.

Point Browser Sync to Tunnelss-generated SSL Certificates

BrowserSync has a bunch of configuration options. Some are inaccessible via the command line interface and need to be specified in a javascript file passed to the command line app.

Here’s how to configure BrowserSync to use the tunnelss-generated SSL certs to serve the secure web sockets it uses for syncing:

// https://www.browsersync.io/docs/options module.exports = { // "logLevel": "debug", "files": [ '**/*.css*', '**/*.html*', '**/*_controller.rb', '**/*.md' ], "https": { "key": process.env['HOME'] + "/.tunnelss/key.pem", "cert": process.env['HOME'] + "/.tunnelss/server.crt" } };

Throw this configuration file in bs-config.js in the root level of your project and start the BrowserSync server with:

browser-sync start --config bs-config.js Connect Your Rails (or Sintra) App to BrowserSync

To connect your application to the BrowserSync server, throw this simple javascript tag in your layout:

<% if Rails.env.development? %> <script type='text/javascript' id="__bs_script__">//<![CDATA[ document.write("<script async src='https://HOST:3000/browser-sync/browser-sync-client.js'></script>".replace("HOST", location.hostname)); //]]></script> <% end %>

Note that the above snippet does not define a browser sync version in the javascript. This makes this code a bit more resilient to browser sync updates.

I prefer this simple JS snippet to a middleware (like rack-livereload) that inserts the JS snippet into your site automatically. Keeping this code in your layout makes it easy to upgrade the code in the future, and is more declarative to new developers working on the project.

Continue Reading

Using HTTPS Locally: Pow, SSL, Rails, and Apache

Using HTTPS local development or testing environments is a hassle. A common practice is to disable SSL in development, but I’ve had too many cases of minor bugs creeping in when routing works differently between environments. I also don’t like manually having to let my browsers know that a self-signed certificate is valid.

Here’s the configuration that I use to easily add https support on my development machine to any application served—or proxied—through port 80.

Pow

I use Pow as my development rails server. However, because I often work with other languages as well, I run Apache (you could just as easily use nginx) and reverse proxy Rails application requests to Pow.

To do this, you’ll need Pow to bind to a port that is not port 80. Here’s how to configure Pow to use port 88.

Apache

I use nginx in production environments, but I’ve been using Apache on my local development machines for years and just haven’t gotten around to changing my dotfiles to use nginx. You could just as easily use nginx here.

In any case, here’s what I was looking to achieve in my apache config:

Throw error logs in ~/Sites/logs Support vhosts + xip.io domains Access WordPress sites using site-name.wp.dev Access Rails applications using site-name.dev. These requests need to reverse proxy to pow on port 88. Support proxying *.test domains to a customized port. Having a *.test domain allows you to run SSL-enabled integration tests for a multi-domain Rails application against the rspec-run rails server. Checkout my series on rails testing for more details on why this is important.

I was able to get all of this working with a single file thrown in /etc/apache2/other.

Rails: Tunnelss to the Rescue

Tunnelss is a little gem that brings it all together. It looks at your pow config, generates self-signed certificates for those domains, and adds that certificate to your keychain so your browsers accept the self-signed certificate. Brilliant.

The only downside here is you must keep tunnelss running in the background. Right now, the project doesn’t have a launchd plist available. So, for now, you have to start the application manually on each system restart.

Continue Reading

How to Refund a Customer Deposit using NetSuite SuiteTalk

When refunding a NetSuite CustomerRefund or CashSale you’ll add it to apply_list:

refund.apply_list = { apply: [ { doc: 123, # internalId of the CustomerRefund apply: true } ] }

Refunding a CustomerDeposit works a bit differently. If you inspect the SuiteTalk XML response for a CustomerRefund created for a CustomerDeposit it will appear under the apply_list XML tag. If you use that XML tag when creating the CustomerRefund you’ll get the following error:

Unable to find a matching line for sublist apply with key

Instead, you need to use the deposit_list tag:

refund.deposit_list = { customer_refund_deposit: [ { doc: 123, # internalId of CustomerDeposit apply: true } ] }

Continue Reading

7 Categories to Help Guide Your 2016 Goals

Results follow clarity, and clarity comes from clear definition. Writing is the best way to clearly define your thoughts (one of the reasons you should start a blog!).

Here are my goal categories, in order of long-term priority. Explicitly defining these categories has helped me during my goal planning process to identify which categories needs the most attention this upcoming year, and ensure that my goals align against these categories:

Spiritual Marriage Health Intellectual Financial Work Relationships

This ordering doesn’t mean that work won’t come before my intellectual life (i.e. reading, conferences, learning, etc). It does mean, for me, over the long-term I need to ensure that my intellectual life is made a priority over work success.

Although simple, the exercise of defining and prioritizing the different categories of your life, is incredible important.

Continue Reading

2015 Goals Retrospective

I’ve been making intentional yearly goals using Michael Hyatt’s Best Year Ever program for the last couple years. The simple workbook that Michael provides is effective in reviewing the past year, and defining goals for the upcoming year.

A “retrospective” is a process common in Agile Software Development, but I’ve started applying it my personal life planning lately. I made a lot of progress on key goals this past year, but still made a lot of mistakes; below is a retrospective on my 2015 goals.

Here’s what worked:

Getting clear on my goals, and the reasons (or motivation) behind those goals. Adjusting my actions and strategies to align against my goals.

Here’s what didn’t work:

I didn’t track my progress against my goals in a consistent and disciplined way. Although my goals were trackable (a key element of a successful goal!) I didn’t track against the metrics embedded in the goal. I didn’t adjust my actions and strategy, even though it was clear that my original strategy wasn’t bringing me towards my goals fast enough–and in some cases–was just the plain wrong strategy. I didn’t have a process in place to remove goals that weren’t right anymore. A goal that makes sense at the beginning of the year may not make sense mid-way through the year, and that’s ok.

My plan is to fix what went wrong with two simple tweaks:

I’m setting up a monthly recurring task in my task management application (todoist) to review progress on goals in a simple google spreadsheet. I’ve blocked off a day each quarter for a “quarterly checkin” to ensure that 1) all my goals are still the right goal and 2) the strategy and actions aligned against each goals are correct.

I’m thrilled to jump into 2016 with all I’ve got. I’m excited about these changes to my goal planning process; I’ll report back next year to see if it worked!

Continue Reading

What a Freezing Cold Pond Taught Me

A couple weeks ago, I was on a hike in a state park with some old friends. Part of the hike included a small pond with a great dock. All of us walked out on the dock, and continued talking while enjoying the view. It was mid-November and was a really cold day.

One of the guys stripped down and jumped into the pond.

A couple minutes later a couple of the guys followed.

After getting out of the pond and shivering for the next couple minutes, they all felt great; invigorated by the experience.

It’s easy to get comfortable, and resist making a hard decision or a large change. This experience reminded me that it’s possible to do something incredibly uncomfortable or challenging and come out of it just fine, and in most cases much better.

The fears that often keep me from making a hard decision or doing something risky can be easily eliminated by remembering how resilient, creative, and innovative one can be when under pressure.

Continue Reading

Determine Deposited Status of CustomerRefunds in NetSuite

Most payment and refund records in NetSuite have a straightforward way to determine if they’ve been deposited or not. The CustomerRefund is one exception: there is no way to determine from the GUI, or from the SuiteTalk API response for a CustomerRefund, if a given CustomRefund has been linked to a deposit record.

However, you can search for CustomerRefunds which are deposited or undeposited using a couple poorly documented search filters:

NetSuite::Records::CustomerRefund.search( criteria: { basic: [ { field: 'type', operator: 'anyOf', value: [ '_customerRefund' ] }, { field: 'applyingLinkType', operator: 'noneOf', value: [ '_depositRefundCheck' ] }, { field: 'mainLine', value: true }, { field: 'account', operator: 'anyOf', # undep funds account reference value: [ NetSuite::Records::RecordRef.new(internal_id: 6) ] } ] }, preferences: { page_size: 250 } )

Continue Reading

Are You Being Deliberate About Long-term Goals?

Recently, I met with a mentor about some of my past and future goals. After listening and understanding my goals, he started to dive into the motivation behind my goals.

Why did I want to build that product? Why was I interested in that type of business? What did I want my life outside of work to look like? What type of people do I enjoy working with? Am I working with those people? What type of work did I enjoy? What type of work am I excellent at? What type of lifestyle do I want to live?

I had good answers to the first round of questions, but as he kept digging I realized my answers were becoming more and more thin, and I had a lot of thinking to do.

I’m a planner by nature. I’m a checklist-driven high achiever who loves to build, create, and get things done. What the questions by this trusted mentor made me realize is my thinking and planning had been very short-term and short sighted.

My goals and ideas were aimed at the next 1-3 years and not the next 5, 10, or 15 years.

He challenged me to get intentional. To be deliberate about defining what I want to achieve. To get clarity on what I want all aspects of my life to look like: professional, family, spiritual, financial, social, etc. I was challenged to define in detail what I’m excellent at, what there is a market for, and what I’m passionate about; and to develop and find opportunities at the intersections of those three things.

It’s our duty to strive towards greatness in our lives, and through my time with this mentor I realized that I was falling short. Are you being deliberate and intentional about defining and striving towards greatness in your life?

Continue Reading

Get a Dedicated, Free, High Quality Conference Line

Premium services often end up being cheaper.

This doesn’t meant that all premium services are expensive. Systems are being disrupted at such a rapid pace you can often find incredible services – like a free virtual fax machine – completely free.

One of these services is UberConference. Even if you run a one man shop (like I do!) you should signup for UberConference and use it exclusively for calls.

Here’s why:

Hangouts is not reliable for phone calls. They have a great dial out feature, but I’ve been on a couple calls where the call connection kept dropping out. It was embarrassing and made me lool sloppy. Calling someone’s cell, or having them call you, often creates a coordination problem. What if you or they are a couple minutes late? You then have to call again, text them, email, etc to adjust coordination. Using a conference line eliminates this problem completely.

I’ve also found that a call is often more effective than trying to use a video conference, especially if it’s a one-off conversation or if it’s more of a prospecting call. Phone calls are low friction and globally compatible: everyone has a phone and can use it from anywhere. Video conferencing software still frequently fails and can make the start of a conversation awkward and jerky while you both try to get your conference software working.

Continue Reading

Why the Right Premium Services are Always Cheaper

By nature, I’m frugal. I love getting a great deal, and getting the most of out of my purchases. When I was fifteen I got a new MacBook Pro for free by working those “get a free MacBook pro” ponzi schemes online: my obsession with a great deal started early.

I’ve learned that it’s often worth paying for premium services when your time is at stake. Not only your current time, but time that a premium service could possibly save in the future.

Opportunity cost is a real thing: it’s important to consider what you can’t do or time that could be possibly spent on fixing a future problem with the service or product.

Here are a couple of failures from recent memory:

Low Cost HSAs. I have a high deductible health insurance plan coupled with a health savings account. I picked one from a big name bank, with average ratings, and the best fee structure. Wrong choice: the time spent on phone, faxes (no ability to communicate over email??), etc have incurred most cost in terms of time than I ever saved in fees. Local Banks. My local bank has a great fee structure and a convenient location nearby. However, they are lagging behind in keeping up with tech advancements. Because of their remote deposit limitations, I’ve lost lots of time driving to and from the bank. I should have signed up with Simple or BoA. Budget Home Router. Anytime I spend fiddling with router settings is time lost on better, more interesting problems. I used to attempt to save money on routers: I now buy the most expensive router I can get. Price Shopping. Amazon has great shipping, customer service, review system, etc. It isn’t always the cheapest. However, it’s not worth my time to shop around for a better price. Amazon is nearly always within 10-20% of the best price – and most of the time it is the best price out there. It’s not worth my time to price shop. Low Cost Phone Service. One dropped business call and the $10 you saved that month on your cell phone bill most likely isn’t worth the perceived sloppiness on your end.

Continue Reading