RSSAmplifier

Blog

Adam Albrecht

adamalbrecht.comRSS feed ↗29 posts

Latest posts

Home Cooked Apps

This article really spoke to me. I end up not building things all the time because I’m worried about product market fit, which tools to use to scale, etc. Instead, I need to lean into scratching my own itch and let it evolve however it may. Worst case scenario, I’ll build something useful for one person. The author’s favorite family communication app shut down, so he built his…

Add a Little Safety to your Elixir Structs with TypedStruct

I’m working on an Elixir app at the moment and really enjoying it, but some of my recent dabbling in the type-safe worlds of Elm and Crystal have left me desiring a bit more structure in my code. The app I’m building involves a multi-step data transformation and so I have a data structure to properly represent this process. But since Elixir is a dynamically typed language, you…

Upcoming Phoenix Authentication Solution

I’m in the middle of writing an application in Elixir and Phoenix , so when I saw a link to an article by José Valim on an upcoming authentication solution for Phoenix, my initial reaction (before reading it) was negative. José is the author of the Devise framework for Ruby-on-Rails, so I assumed it was going to be the same idea, but for Elixir and Phoenix. I’ve implemented Devise in a…

JavaScript Sprinkles with AlpineJS

I’m a big of ReactJS , but sometimes it is way too heavy for what I need. The majority of the applications I create are server-rendered and just need some “sprinkles” of JavaScript. In the past, I’ve leaned on jQuery for this, but I’m not a fan of the imperative nature of it. Recently, I stumbled upon AlpineJS, which is a super minimalist framework that lets you write…

Enable Spell Checking in Vim for Markdown and Git Commit Messages

I had a ridiculous typo in a Git commit message recently, so I decided to explore spell checking in Vim. As it turns out, it’s extremely easy. I only wanted it enabled for Git commit messages and markdown, so I added the following to my vimrc / init.vim: " Spell-check Markdown files and Git Commit Messages autocmd FileType markdown setlocal spell autocmd FileType gitcommit setlocal spell By…

Dark Mode and other site updates

Inspired by iOS’s new dark mode (and halloween!), I decided to a dark mode to the website using the new prefers-color-scheme media query. It was surprisingly easy to do. After I’d changed the This took care of 90% of it: @media ( prefers-color-scheme : dark ) { html { background-color : #19222b ; color : #eee ; } .page-wrapper__inner { background-color : #222f3b ; color : #eee ; } }…

Quickly Convert 4 Spaces (or Tabs) to 2 spaces in Vim

Here’s a handy Vim command that I find myself searching for often. It could easily be made into a function in your vimrc. " 4 spaces to 2 spaces %s;^\ ( \s\ + \ ) ;\ = repeat ( ' ' , len ( submatch ( 0 )) / 2 ) ; g " Tab to 2 spaces %s /\t/ / g

Get the Previous Expression Value in IEx

When using Elixir, I’ve long missed the special _ helper from irb that returns the result of the previous expression. Sometimes I actually type it out of pure habit. Little did I know that Elixir has the same thing, except better. IEx.Helpers has a function v(n \\ -1) that returns the value of the nth expression in the session history. So v alone returns the previous expression and v(-2)…

Ruby Symbol and String Array Shorthand

Ruby has some handy Array shorthands, but I always forget which is which, so I thought I should write them down. Symbol Array Shorthand: %i{foo bar} # => [:foo, :bar] String Array Shorthand: %w{foo bar} # => ["foo", "bar"] Both also work with square brackets %w[a b c] or parenthesis %i(a b c)

Running Elixir tests in VSCode

In Vim-land, I use the vim-test plugin for quickly executing tests from a command line shortcut 1 . I wanted to reproduce this behavior in Visual Studio Code , but I couldn’t find an extension that worked in multiple languages (namely, Ruby, Elixir, Javascript, and Elm). I’m mostly just using VSCode for Elixir, but I still liked the idea of finding a more general purpose solution. So…

SSH Tunnels into Production Rails Database

Today I needed to access a production database for my Rails app directly using a GUI application on my mac, so I figured out that this can be done by creating an SSH tunnel like so: ssh -Ng -L <local-port>:<remote-host>:<remote-port> <user>@<remote-host> ssh -Ng -L 3307:100.64.26.11:3307 adam@100.64.26.11 And then, in your Rails app, update the database.yml as if you were connecting to a local…

VSCode + ElixirLS = 👍👍

I&rsquo;ve played around with VSCode here and there, but as a fairly picky Vim user who doesn&rsquo;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 ,…

Rails presence method

I use Rails&rsquo; 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…

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&rsquo;t quite as enthusiastic as their service in general, but it does have some nice features. Pros: Server Side Can&rsquo;t be blocked by Ad-Blockers Tracks requests of non-web-page…

TIL: Pass in an ActiveRecord Object to a where string

I&rsquo;m surprised I didn&rsquo;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&rsquo;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 )…

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…

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&rsquo;t like about the old website: As a developer with some design chops, I never liked the fact that I hadn&rsquo;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…

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&rsquo;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…

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&rsquo;ll do the same, but using the React ecosystem . But even if you&rsquo;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…

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&rsquo;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 &ldquo;sprinkles&rdquo; and then Backbone. But then recently, I started playing with Facebook&rsquo;s React framework. And while I&rsquo;m still not quite as productive…

Authenticating your Angular / Rails App with JSON Web Tokens

UPDATE: There have been some changes in the JWT Gem that make some of the below not work exactly right (it&rsquo;ll still be about 90% the same). Specifically, they added expiration support. See my post on the same topic, but using React.js . The server side code in this post will work just as well with Angular. Overview I&rsquo;m a big proponent of rolling your own authentication solution,…

Authorization with Angular.js and UI-Router

While working on an angular.js application recently, I found myself needing some form of authorization logic (not to be confused with authentication / login). I needed to restrict content in my app based on a user&rsquo;s role as well as some other factors. At first, I created a single AuthService service that dealt with login, authorization, and session management. But this felt messy and…

Building your Angular app with Gulp.js

As my work has transitioned from traditional web apps to thick-client Javascript apps (primarily using Angular), Grunt has become essential in my workflow. Grunt is a nice tool and it gets the job done. But there was always something I didn&rsquo;t like about it that I couldn&rsquo;t quite articulate until I discovered Gulp.js . Whereas in Grunt, you create a json configuration file, Gulp is just…

Pre-Filling PDF Form Templates in Ruby-on-Rails with PDFtk

In a recent post , I talked about how to generate PDF reports in Rails using Prawn. This approach is great for generating PDF&rsquo;s with lots of data tables and other variable-length content. But an alternative situation is when you already have a template authored in an application such as Adobe Acrobat and you want to populate it with data from your database. This makes it more difficult to…

A Better Onboarding Experience in your Angular.js Application

&ldquo;Onboarding&rdquo; is one of those things we sometimes forget about when developing an application, but it really deserves more attention. Showing the user how to use your app can be critical in retaining them. Some people might say that if you need onboarding, your app just needs to have a better UX, but I don&rsquo;t think this is practical in all situations, particularly complex business…

Generate Clean, Testable PDF Reports in Ruby/Rails with Prawn

I generally hate PDF&rsquo;s. The file format is complex and designed to mimic physical paper documents, which really has little to do with the web. But unfortunately, PDF&rsquo;s are still very common and often expected, particularly when working on businesses applications. I have a legacy ruby-on-rails application with a number of PDF reports and I recently took the time to refactor them in a…

How to Create a Simple Modal Dialog Directive in Angular.js

Modals are Easy I&rsquo;ve used a dozen or so modal / lightbox plugins over the years, almost exclusively jQuery-based. But you know what I didn&rsquo;t realize until fairly recently? Modals are easy to build yourself from scratch. So let&rsquo;s make one in the Angular fashion. The Requirements I want to be able to create a modal with the following HTML: <modal-dialog show= 'modalShown' width=…

A Better Date Picker in Angular.js

UPDATE (March 14th, 2015) When I first wrote this library, I didn&rsquo;t have a great understanding of the ngModelController API , nor good directive design. So I wouldn&rsquo;t recommend this library anymore. I started on a replacement library here , though it&rsquo;s not quite ready for production use. I wasn&rsquo;t particularly happy with any of the datepicker directives out there for…

How to Auto-Save your model in Angular.js using $watch and a Debounce function.

The Problem Currently, I&rsquo;m working on an Angular app that is very form-centric. Fields and fields and more fields. I want to make the form-filling process as quick and painless as possible, so I&rsquo;m trying to implement auto-save. Update (March 19th, 2014) I&rsquo;ve done quite a bit more auto-saving on my current project and I&rsquo;ve updated my post with some slightly better methods.…