Blog

RSS Feed

VSCode + ElixirLS = đź‘Ťđź‘Ť

I’ve played around with VSCode here and there, but as a fairly picky Vim user who doesn’t do TypeScript, I never quite understood the hype.

Today I started up a new Elixir / Phoenix project (more on that to come) and tried out the Elixir Language Server Extension and the integration is very impression. Code completion, debugger support, automatic inference of Dialyzer Typespecs, documentation on hover, and more….

I don’t expect to be using VSCode as my standard editor (again, picky Vim user1), but I think I’ll stick with it on Elixir projects.


Read More...

Rails presence method

I use Rails’ present? method constantly, but recently I stumbled across the presence method.

In the past, I have often found myself doing the following because params[:foo] could be nil or a blank string.

foo = params[:foo].present? ? params[:foo] : "something else"

I hate that i have to write params[:foo] twice. But the presence method is handy for this case. It returns nil if the item is nil or a blank string, but otherwise returns the value.

foo = params[:foo].presence || "something-else"

Netlify Analytics First Impressions

My new website is hosted on Netlify, which is an awesome service for hosting static websites. Recently, they launched an Analytics Platform as an alternative to Google Analytics. My impressions of this new tool isn’t quite as enthusiastic as their service in general, but it does have some nice features.

Netlify Analytics Screenshot

Pros:

Server Side
  • Can’t be blocked by Ad-Blockers
  • Tracks requests of non-web-page assets like RSS feeds, images, etc
  • No impact on your client side performance since there’s no Javascript library
Privacy Centric
  • Isn’t connected to an ad network...

Read More...

TIL: Pass in an ActiveRecord Object to a where string

I’m surprised I didn’t already know this, but if you have an ActiveRecord where statement that references an id column, you can just pass in an object and it will pass in the object’s id, not the string representation of the object.

company = Company.find(1)

User.where("users.company_id = ?", company)
# is equal to
User.where("users.company_id = ?", company.id)

So when you create named scopes, you don’t have to do the song-and-dance where you check to see if the object is a model or an integer, as shown below.

scope :by_company, lambda { |company|
 ...

Read More...

Lookup IP Address & Location via the Command Line

With ifconfig.co, you can lookup your external IP Address and Location Information using a simple curl command. You can use it like so:

$ curl ifconfig.co/json
{
  "ip": "96.27.202.202",
  "ip_decimal": 1612409628,
  "country": "United States",
  "country_iso": "US",
  "city": "Columbus",
  "hostname": "d27-96-101-101.nap.wideopenwest.com"
}

$ curl ifconfig.co/city
Columbus

$ curl ifconfig.co/country
United States

Website Revamp! And introduction to my Work Journal.

My website has gone slightly stagnent lately, so I decided that it was time for a revamp. There were a few things I didn’t like about the old website:

  • As a developer with some design chops, I never liked the fact that I hadn’t designed my website myself. I was using the Hyde theme for Jekyll.
  • I felt boxed in by the fact that all my previous posts were longer-form articles.
  • While Jekyll is a great tool, it’s very blogging-centric, and I wanted to add new types of content.

So I re-designed the website from scratch using Middleman. I started with Thoughtbot...

Read More...

Run your Ruby tests quickly and easily using Vim and Tmux

In order for testing to become part of your development workflow, it needs to become a habit. And like any habit, its biggest enemy is neglect. Too often I’ll be in a rush and not add tests to my code for a day, and that turns into a week and then a month, and suddenly I have an app where half of my codebase is untested and the other half has breaking tests. There are many things you can do to help keep this habit (hooking up a CI server immediately comes to mind), but an important one is to make running your tests as quick and easy as possible.

One way I do this is by making my ruby tests (either Rspec or Minitest) extremely easy to run while I’m using Vim (and Tmux). With one quick keystroke, I can run the current test file or individual test in a new Tmux pane.

Read More...

Authentication with JSON Web Tokens using Rails and React / Flux

In a previous post, I went over how to add authentication to your Rails + Angular app using JSON Web Tokens (JWT). This time, I’ll do the same, but using the React ecosystem. But even if you’re using another front-end framework (Angular, Ember, Backbone), this post will be helpful because it fixes some issues with the previous server-side code that broke due to a change in the jwt gem.

Read More...

How to Replace the Angular Stack with React plus a few NPM modules

As you can tell from the content of my blog posts, I’ve been practicing and preaching Angular.js for quite some time now. It is an extremely productive web framework that felt like a big step forward from my days doing jQuery “sprinkles” and then Backbone.

But then recently, I started playing with Facebook’s React framework. And while I’m still not quite as productive as I was with Angular, I absolutely love the code that I’m writing. And on top of that, it has opened my eyes to a whole new paradigm for creating user interfaces.

Read More...