Running rake tasks from within Ruby on Rails code

John Bachir's Code Blog
July 14, 2021

If you want to run rake tasks from within an already-running rails instance (such as when using ruby-clock) without forking and making a new rails process (system 'rake foo:bar'), it's very possible, but there are a few things to keep in mind.

First, load the jobs once when the app is being initialized (I think this is . . .

Read More

How to create a new column in Postgres with existing rows backfilled with a different value from the default

John Bachir's Code Blog
December 20, 2020

The best approach for creating a new column that has a default has changed since Postgres 11. In the case where we want the existing rows to have a different value from future created rows (e.g. a boolean which signifies if a user should see the onboarding tour), the best approach has also improved significantly in a way that perhaps . . .

Read More

How to figure out what processes are using IO on MacOS / debugging mysterious performance problems

John Bachir's Code Blog
December 06, 2020

This blog post is a loose documentation of some problems I've had with my mac lately and how I maybe diagnosed them, for my own documentation and maybe some of it will prove useful to people who find it when searching.

Lately I've been having mysterious problems on and off with my Mac laptop. Sometimes it almost seems like a . . .

Read More

The New S3 is Magic!

John Bachir's Code Blog
December 06, 2020

I recently tweeted

in between seasons, Star Trek writers freelance as persistence system marketers
Silvrback blog image

(here's the AWS announcement)

And it blew up and created wild controversy across the internet (not really, it got zero likes).

What I mean by this is "no impact" is doing a lot of . . .

Read More

How to have xargs use its input in an arbitrary invocation

John Bachir's Code Blog
October 09, 2020

Here's a common pedestrian use of xargs:

ls *.rb | xargs echo

What this does is invoke echo on a big list of all the files found by ls *.rb

But let's say you want to use the output of ls *.rb in a more complicated way? You don't want the entire list to just be tacked onto the end of whatever command you give . . .

Read More

How to use xargs to invoke an executable once for each argument

John Bachir's Code Blog
October 09, 2020

You might have used xargs before like this:

ls *.rb | xargs echo

This will invoke echo once, with all the files passed in.

But what if you want to invoke echo one time for each file? The answer is very easy and not very clearly described in the docs. From man xargs

-n number

Set the maximum number . . .

Read More

How to show the current TotalSpaces space name in the menu bar

John Bachir's Code Blog
May 04, 2020

TotalSpaces is great! One flaw is you can't put the name of the current space in the menu bar. Only the number. Here's a workaround, possible because it has an API!

  1. Install the ruby gem sudo gem install totalspaces2
  2. Install TextBar
  3. Set up a TextBar menu item
    1. ruby -r'totalspaces2' -e . . .

Read More

Archive
   Subscribe by email and never miss a post.